Protect certain routes with auth middleware
MODIFY
app/Exceptions/Handler.php
app/Exceptions/Handler.php
@@ -60,6 +60,6 @@ class Handler extends ExceptionHandler
return response()->json(['error' => 'Unauthenticated.'], 401);
}
- return redirect()->guest(route('login'));
+ return redirect()->guest(route('login_get'));
}
}

MODIFY
routes/web.php
routes/web.php
Route::get('/login', 'LoginController@index')->name('login_get');
Route::post('/login', 'LoginController@store')->name('login_post');
+Route::group(['middleware' => ['auth']], function () {
Route::get('/dashboard', 'DashboardController@index')->name('dashboard_get');
+});
Route::get('/logout', 'LogoutController@index')->name('logout_get');

Protect certain routes with auth middleware