I want to check user type when they log in and apply function
In my middleware
, I have this code
public function handle($request, Closure $next)
{
$user = Auth::user();
if ($user->isBasic()) {
$previous_session = $user->session_id;
if ($previous_session) {
\Session::getHandler()->destroy($previous_session);
}
Auth::user()->session_id = \Session::getId();
Auth::user()->save();
return redirect(route('home'));
}
return $next($request);
}
In my User model
, I have this
public function isBasic()
{
return $this->role=='basic';
}
I have already registered the middleware in Kernel
'basic' => \App\Http\Middleware\CheckSession::class,
And I passed it to my LoginController like this
public function __construct()
{
$this->middleware('basic');
}
But when it tried to visit the login controller, it says
Call to a member function isBasic() on null
I am a beginner in Laravel and I don't know what to do