Search code examples
phphtmllaravelroutesmiddleware

Laravel: InvalidArgumentException middleware error


So I have a view called dashboard.blade.php and I only want users that are logged in to access this page. I have used a middleware to block access.

This is my route to dashboard:

 Route::get('/dashboard', 'PostController@getDashboard')->name('dashboard')->middleware('auth');

It does what it is supposed to do by letting logged in users to access the dashboard, but when a user that is not logged in tries to enter that page it gives the following error:

InvalidArgumentException
Route [login] not defined.

I understand that it is working because it is blocking the user. However, how would I go about redirecting the user back to the login page as an example?


Solution

  • The application can't find any route named login. So you need to create a login named route. Something like:

    Route::get('/login', 'AuthController@login')->name('login')