-1

I make an online store in which I have two login places. /checkout (in cart) and /login.

Can i do it in the existing method to make redirect look like this?
if i login in /checkout ->redirect('/checkout').
(for loggin in /login) it stays like it is /redirect('/')

Matthijs
  • 2,483
  • 5
  • 22
  • 33
abaka3
  • 21
  • 4

2 Answers2

0

I would solve that by using the redirectTo() method in the Login Controller and checking which route is sending the request through the path() method. You have to name the routes for it to work though. So in your login Controller you'll have this;

use Illuminate\Support\Facades\Route;

protected function redirectTo(){
    if(Route::currentRouteName() == 'login'){
        return '/';
    }else if(Route::currentRouteName() == 'checkout'){
        return '/checkout';
    }

}

more info on how to get the route name here

and info on the redirectTo() function here

Try it out, tell me what happens..

Edgar
  • 472
  • 6
  • 17
  • Unfortunately, your idea didn't work. in the comment I placed the solution that I used – abaka3 May 11 '19 at 15:37
  • I saw your answer, I feel like the use of `strpos()` is not robust but hey, if it works, it works.. – Edgar May 11 '19 at 15:54
0

only this solution works:

protected function redirectTo() {
    if(strpos(URL::previous(), 'checkout')) {
        return '/checkout';
    } elseif(strpos(URL::previous(), 'login')) {
        return '/';
    }
}
abaka3
  • 21
  • 4