Description
I am not able to restrict user to redirect login page when it is logged in and also unable to restrict to redirect on dashboard when it is not logged in.
please give idea.
Yes it's very simple in Laravel. You achieve this functionality using middleware, in middleware you can add the logic that if the user is logged in then he/she can visit the dashboard, and if the user is logged in and want to visit the login page, he will be redirected on the dashboard because he is already login.
In Laravel auth middleware comes default which checks that user is login or not
How to apply this middleware?
Simply go to your routes files and call this middleware like this ->middleware('auth');
Example route with middleware
~~~
Route::get('/home', [HomeController::class, 'home'])->middleware('auth');
~~~
That's it
1 Like 1 Comment
Glad to help you.