How do I set the homepage (/
) to the login screen in Laravel 5.3?
I have a routes file :
Route::get('/', function () {
return view('welcome');
});
I have set up the basic auth scaffolding with the command php artisan make:auth
and have set up my db tables too.
But I'm struggling to understand how to set the homepage to always go to the login screen if the user is not authenticated? Surely this is just me being stupid right?
Just copy this into your routes. php in place of Route::auth() and then change the paths to suit your use case. Route::get('mysite/login', function() { Route::auth(); });
The attempt method accepts an array of key / value pairs as its first argument. The values in the array will be used to find the user in your database table. So, in the example above, the user will be retrieved by the value of the email column.
I just needed to specify the middleware('auth')
for my route:
Route::get('/', function () {
return view('home');
})->middleware('auth');
Route::get('/home', 'HomeController@index');
This way if you're not logged in it will redirect to login automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With