简体   繁体   中英

Call separate Route after Register and login in laravel 5.2 Auth?

I want to call separate Route after registration and login in laravel 5.2 Auth.like after login call dashboard Route and after registration call add_project Route??

**protected $redirectTo = '/dashboard';**

how i play with it?? for that specific case.

The best method is to use the Auth middleware built in to laravel. You can setup a default login route which unathenticated routes should be sent to, and allow all authenticated users into the route.

This is the best method because it can be applied to a group of routes, meaning you don't have to manually add the rule to each route you want protected. Just group them together.

Route::group(['prefix' => 'auth', 'namespace' => 'Auth'], function () {
    Route::any('login', 'AuthenticationController@anyLogin');
});

Route::group(['middleware' => 'auth'], function () {
    Route::resource('person', 'PersonController');
});

Open /App/Http/Controllers/Auth/AuthController.php and change line 31 shown below.

protected $redirectTo = '/';

to

protected $redirectTo = '/dashboard';

Now open file /vendor/laravel/framework/src/Illuminate/Foundation/Auth/RegistersUsers.php. here inside the register method on line 53, right after this line:

$validator = $this->validator($request->all());

add this line:

$this->redirectPath = '/add_project';

So here the $redirectTo path is used for both register and login redirection. after the first change, successful login will redirect to the dashboard. but registration will redirect there too. so we have to modify the redirectPath() method which as final proccess is responsible for the redirection. this method (AuthController > RegistersUsers trait register method > RedirectsUsers trait > redirecPath method) checks the 'redirectPath' property before it redirects to the default '$redirectTo' path which we changed first. By adding the property the check will redirect directly to the 'redirectPath' path.

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