2016-10-04 68 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 (...) { ... } 
相關問題