How to redirect automatically to a login page when session expired?

You can create a middleware and call all your login page URL between that middleware call in web route file. Below example works if you used Laravel Auth.

Use all your route path between this in web route file:


Route::get('', ['middleware' => 'auth', function () {
//add all your routes here
}]);

Or create your own authenticate file and add that into app/Http/Kernel.php then call your URL like above by passing your middleware name.

If you want different URL to redirect after session time out then you can check user session into specific function and if user session not exist then redirect to your desire URL like below:


if(!Auth::user())
{
return redirect(); // add your desire URL in redirect function
}

You can create a constructor in your class file and add above condition if you want to redirect from all functions call to a specific URL.

Hope this will solve your problem.

Freelancergurus recent blogs :

How to make string case-sensitive through Laravel query?
How to get current URL and its query parameter or string in Angular 5?

Hire Dedicated Laravel developer for your project. Just drop us a line and lets get started.