Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.3 set homepage as login screen

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?

like image 734
user3574492 Avatar asked Jan 15 '17 00:01

user3574492


People also ask

How do I change the default login for Laravel?

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(); });

What is Auth :: attempt in Laravel?

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.


1 Answers

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.

like image 101
user3574492 Avatar answered Oct 11 '22 14:10

user3574492