简体   繁体   中英

Laravel 5.2 Auth and Password route

I saw that Laravel 5.2 change the routes.php use.

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 :

// 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 ?

Thanks for your help !

Since Laravel 5.2, the authentication system is much easier to get up and running. You can simply run this command:

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 article to see other features that are new to Laravel 5.2.

vendor/laravel/framework/src/Illuminate/Routing/Router.php
go for this file auth method, there all routes defined

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');

If anyone have some trouble to access /login and /register with the new authentication system. You should look at the session documentation .

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.

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;
    ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM