When someone tries to visit a page which requires authentication is redirected to a login page. How do I redirect them to their desired page after successful login rather than default link?
Asked
Active
Viewed 130 times
0
-
`return redirect()->intended('dashboard');` I meant something like when a user visits a page and is not authenticated they get redirect to login page. So after login they should return to the page they wanted to visit earlier. The above worked for me – lawkunchi Feb 22 '19 at 11:12
3 Answers
1
See the default login controller file https://github.com/laravel/laravel/blob/master/app/Http/Controllers/Auth/LoginController.php
There is a part with
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
Change that property to your preferred endpoint and they will be redirected accordingly.
Flame
- 6,663
- 3
- 33
- 53
0
Open app/Htpp/Controllers/Auth/LoginController there is one parameter called redirectTo change it any route you want
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
or if you want to use some logic you can create a method called redirectTo
public function redirectTo(){
...
return 'some route';
...
}
Malkhazi Dartsmelidze
- 4,783
- 4
- 16
- 40
0
All you have to do is override the redirectTo() function on your Controllers/Auth/LoginController.php like this:
protected function redirectTo()
{
return '/desired-page';
}
Juan Carlos Ibarra
- 1,299
- 14
- 15