Laravel 5 - After login redirect back to previous page

前端 未结 13 2338
广开言路
广开言路 2020-11-30 04:41

I have a page with a some content on it and a comments section. Comments can only be left by users who are signed in so I have added a login form to the page for users to si

13条回答
  •  醉梦人生
    2020-11-30 05:17

    For Laravel 5.4, following code worked for me by just updating LoginController.php

    use Illuminate\Support\Facades\Session;
    use Illuminate\Support\Facades\URL;
    
    
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'logout']);
        Session::put('backUrl', URL::previous());
    }
    
    
    public function redirectTo()
    {
        return Session::get('backUrl') ? Session::get('backUrl') :   $this->redirectTo;
    }
    

提交回复
热议问题