Intended lost after login
Hello :)
i'am using the authentication controllers included with Laravel. So i have the code below:
- in /routes/web.php:
Auth::routes();
Route::get('/home', function () { return view('index'); });
Route::get('/mypage', 'MyController@index');
-
in /app/Http/Controllers/MyController.php
public function __construct(MyRepository $myRepo) {
$this->middleware('auth'); ....}
So i need to be sign in to acces to '/mypage', but i never been redirect to previous page after that. It's always redirect to '/home'
So i change the function in /app/Http/Middleware/RedirectIfAuthenticated.php
public function handle($request, Closure $next, $guard = null) {
if (Auth::guard($guard)->check()) {
return redirect()->intended('/home');
}
return $next($request);
}
And add this function to /app/Http/Controllers/Auth/LoginController.php
public function showLoginForm() {
// Get URLs
$urlPrevious = url()->previous();
$urlBase = url()->to('/');
// Set the previous url that we came from to redirect to after successful login but only if is internal
if(($urlPrevious != $urlBase . '/login') && (substr($urlPrevious, 0, strlen($urlBase)) === $urlBase)) {
session()->put('url.intended', $urlPrevious);
}
return view('auth.login');
}
But the same result, always redirect to '/home', so i search in
/vendor/laravel/framework/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php
And i found that function:
protected function sendLoginResponse(Request $request) {
$request->session()->regenerate();
$this->clearLoginAttempts($request);
return $this->authenticated($request, $this->guard()->user())
?: redirect()->intended($this->redirectPath());
}
$request->session()->regenerate(); // regenerate the session so the value in intended() will be deleted!!!
so automatically
return redirect()->intended('/home'); // return always '/home'
Please, do you have any idea how to fix this?
thanks :)
Please or to participate in this conversation.