Saturday, March 4, 2017

Call to a member function isAdmin() on null

Hey I'm learning laravel v5.2 and working on user authentication system and making some check using User modal to check is login user is admin or not.But when I'm try to get login user by using Auth::user() I'm getting blank value in return.

 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', 'HomeController@index');

});



via Ashish Mehra

Advertisement