简体   繁体   中英

How can i continue the user to the requested page after authenticated?

I was wondering how can i continue the user requested page after authenticated with laravel 5.2 ? Do i need to set a session or laravel has something to do this?

Example: I am not registered yet. I am looking for a product. I click "Order Now" button. Then i go to login/register page. After getting authenticated i go to the order page with the product that i want to order.

Sorry for my newbie question. May i can get some help on how to make this process right. Or maybe i get some references for this. thanks.

You can use the intended URL method in Laravel.

Eg:

public function authenticate()
{
   if(Auth::attempt(['email'=> $email, 'password'=>$password])
  {
      return redirect()->intended('dashboard');
   }
}

In the above example, the user will be redirected to the 'dashboard' after login if there's no intended URL. Else, he will be redirected to the last page after login.

Intended url is the page from which the user is being redirected to login.

Read more here: https://laravel.com/docs/5.2/authentication#authenticating-users

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