Laravel 5.3 设置主页为登录界面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41656381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.3 set homepage as login screen
提问by user3574492
How do I set the homepage (/
) to the login screen in Laravel 5.3?
如何/
在 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.
我已经使用命令设置了基本的身份验证脚手架,php artisan make:auth
并且也设置了我的数据库表。
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?
但是我很难理解如何将主页设置为在用户未通过身份验证的情况下始终转到登录屏幕?这肯定只是我愚蠢吧?
采纳答案by user3574492
I just needed to specify the middleware('auth')
for my route:
我只需要middleware('auth')
为我的路线指定:
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.
这样,如果您未登录,它将自动重定向到登录。
回答by aceraven777
You can do it like this:
你可以这样做:
Route::group(['middleware' => 'auth'], function () {
Route::get('/', function () {
return view('welcome');
});
});
Just put all the routes that needed authentication inside that middleware group.
只需将所有需要身份验证的路由放在该中间件组中即可。
回答by Raviraj
In laravel 5.4 you can modify the route as Route::get('/', 'Auth\LoginController@showLoginForm');
在 Laravel 5.4 中,您可以将路由修改为 Route::get('/', 'Auth\LoginController@showLoginForm');
回答by Koko Monsef
in laravel in general you can change the url view path to what you want as example
通常在laravel中,您可以将url视图路径更改为您想要的示例
Route::get('/', function () {
return view('auth.login');
});