1
嘿,我正在學習laravel v5.2和工作在用戶身份驗證系統和使用用戶模式檢查是登錄用戶是管理員或不是。但是當我嘗試通過使用Auth :: user()獲得登錄用戶作爲回報,我得到空白值。調用成員函數isAdmin()null
use App\User;
Route::get('/', function() {
$user = Auth::user();
// $user = User::find(1);
if($user->isAdmin()){
return "Admin";
}
return "Normal User";
});
Route::get('/access',['middleware'=>'role',function(){
return "This is middleware";
}]);
Route::group(['middleware' => ['web']], function() {
Route::auth();
Route::get('/home', '[email protected]');
});