重定向回登录后我输入的页面

时间:2018-03-12 08:59:31

标签: php laravel redirect

public function login()
{
$login = EmployeeLogin::whereEmail(request()->email_id)->first();
if ($login) {

 if($login->active == 1){
     if (Auth::guard('employer')->attempt(['email' => request()->email_id, 'password' => request()->pwd]))
     {
        Auth::guard('employer')->user(); 
        return redirect()->intended('/');       
     }
     else{
        return redirect()->route('employer.auth')->with('message','Incorrect Email id or Password');
     }}}}

如何重定向回登录后输入的页面?

我们已经尝试过使用

  • redirect()->back()
  • return Redirect::route('dashboard');
  • 返回Redirect::intended('dashboard');

我正在使用laravel 5.4。

2 个答案:

答案 0 :(得分:1)

使用intended()方法

return redirect()->intended('/');

来自docs

  

重定向器上的intended方法会将用户重定向到他们在被身份验证中间件拦截之前尝试访问的URL。如果目标目的地不可用,则可以为此方法提供回退URI。

答案 1 :(得分:0)

使用Redirect::to()

use Illuminate\Support\Facades\Redirect;

return Redirect::to('dashboard');

routes.php

Route::get('/dashboard', 'Controller@method')->name('dashboard');
相关问题