2016-10-04 38 views

回答

1

你可以试试这个(注意使用use关键字):

$CurrenctUserRoleID = 1; // Some id 

\Cache::rememberForever('Roles', function() use($CurrenctUserRoleID) { 
    return RoleModel 
    ::where('ParentRoleID' >= $CurrenctUserRoleID) 
    ->get(); 
}); 

检查PHP手册:Inheriting variables from the parent scope

1

PHP.net - anonymous functions - 示例#3

你是不是有回调递东西,你是不是回调的调用者。你告诉PHP使用变量从父范围。

function (...) use (...) { ... } 
相关问题