Laravel 5.2 身份验证和密码路由
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34514983/
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.2 Auth and Password route
提问by Jiedara
I saw that Laravel 5.2 change the routes.php
use.
我看到 Laravel 5.2 改变了routes.php
用途。
In fact, the old :
事实上,旧的:
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
don't work now.
现在不工作。
Instead I saw it was better to use :
相反,我认为最好使用:
Route::Auth();
But this method don't provide password and register route like it use to...
但是这种方法不像以前那样提供密码和注册路由......
Actually, I use a solution I saw on Stack Overflow, using get and post method :
实际上,我使用我在 Stack Overflow 上看到的一个解决方案,使用 get 和 post 方法:
// Authentication Routes...
Route::get('login', 'Auth\AuthController@showLoginForm');
[...]
// Registration Routes...
Route::get('register', 'Auth\AuthController@showRegistrationForm');
[...]
// Password Reset Routes...
Route::get('password/reset/{token?}','Auth\PasswordController@showResetForm');
[...]
It's quite awful, so is there a better usage of the 5.2 route.php file for this new Laravel version ?
这太糟糕了,那么对于这个新的 Laravel 版本,5.2 route.php 文件有更好的用法吗?
Thanks for your help !
谢谢你的帮助 !
回答by Bogdan
Since Laravel 5.2, the authentication system is much easier to get up and running. You can simply run this command:
从 Laravel 5.2 开始,身份验证系统更容易启动和运行。你可以简单地运行这个命令:
php artisan make:auth
That will take care of setting up the necessary authentication resources: route definitions, views, etc. There's more info on the subject in the Laravel Documentation. You can also check out this articleto see other features that are new to Laravel 5.2.
这将负责设置必要的身份验证资源:路由定义、视图等。Laravel 文档中有关于该主题的更多信息。您还可以查看这篇文章,了解 Laravel 5.2 的其他新功能。
回答by palash140
vendor/laravel/framework/src/Illuminate/Routing/Router.php
go for this file auth method, there all routes defined
vendor/laravel/framework/src/Illuminate/Routing/Router.php
去寻找这个文件 auth 方法,那里定义了所有的路由
回答by Yagnik Detroja
May This Code Help You..
可以此代码帮助您..
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');
Route::get('auth/confirm/{token}', 'Auth\AuthController@getConfirm');
For Password
密码
Route::get('password/email', 'Auth\PasswordController@getEmail');
Route::post('password/email', 'Auth\PasswordController@postEmail');
Route::get('password/reset{token}','Auth\PasswordController@getReset');
Route::post('password/reset', 'Auth\PasswordController@postReset');
回答by Dennis Adriaansen
If anyone have some trouble to access /login and /register with the new authentication system. You should look at the session documentation.
如果有人在使用新的身份验证系统访问 /login 和 /register 时遇到问题。您应该查看会话文档。
The way (or some parts) of storing sessions is changed. You have to setup a session table. How you can do this will be explained in the doc.
存储会话的方式(或某些部分)发生了变化。您必须设置会话表。如何做到这一点将在文档中解释。
回答by IT Vlogs
You can use alias Route:
您可以使用别名路由:
Route::get('auth/login', ['as'=>'getLogin', 'uses'=>'Auth\AuthController@showLoginForm'];
Route::post('auth/login', ['as'=>'postLogin', 'uses'=>'Auth\AuthController@postLogin'];
In Controller create public function:
在控制器中创建公共函数:
public function showLoginForm() {
return view('auth.login');
}
public function postLogin(Request $data) {
$users = new User();
$users->username = $data->txtUsername;
...
}