1

I'm building a page with 2 logins. So every login has its own blade file. The redirect happens in the LoginController.php i replace this protected $redirectTo = '/page1'; with

function redirectTo(){
        if(true){
            return '/page1';
        } else {
            return '/page2';
        }
    }

It works, that means that it doesn't throw an error. But how can I pass an argument to this function and at which place/file this function is being called?

Sehdev
  • 5,486
  • 3
  • 11
  • 34
  • Does this answer your question? [Laravel 5.4 redirection to custom url after login](https://stackoverflow.com/questions/42177044/laravel-5-4-redirection-to-custom-url-after-login) – Darryl E. Clarke Mar 07 '20 at 05:53
  • No. Cause the redirect should be depend on the way which login (1 or 2) the user useses, not which role the user has. -> 1 user. 2 logins. 2 redirects. So the idea is to pass some value in the submit form, to this function, but i can't figure it out, how and where. –  Mar 07 '20 at 23:34

2 Answers2

0

Create a hidden input field in both your forms as

form1:

<input type="hidden" name="page" value="page1">

form2:

<input type="hidden" name="page" value="page2">

Now in LoginController

 use \Illuminate\Http\Request; // add this line

protected function authenticated(Request $request, $user)
        {


         if (Auth::attempt(['email' => request('email'), 'password' => request('password'), 'verified' => 1])) {
            // Authentication passed...

            if($request->input("page") == "page1") {
               return redirect()->intended('page1');
             } else {
               return redirect()->intended('page2');
             }

        }

        }
Sehdev
  • 5,486
  • 3
  • 11
  • 34
  • I don't want to use role, cause if user1 uses login1 -> page1 if user1 uses login2 -> page2. So the redirect option must imo be in the blade file? or some where else, but i've no idea how to implement it :-( –  Mar 07 '20 at 19:29
  • @dualpeter I have updated my answer. Please check now – Sehdev Mar 08 '20 at 06:04
  • Fantastic!!! It's working out of the box. I can't believe it. Thank you very much. (✿◠‿◠). –  Mar 10 '20 at 01:05
0

Create a function called authenticated() insdide your LoginController.php, then create your own implementation base on what you need to do.

Example:

protected function authenticated(Request $request, $user)
{
  if ($user->role == 'Administrator') {
     return redirect('/admin-page');
  } else if($user->role == 'Guest') {
     return redirect('/guest-page');
  }
  abort(401);
}
Zoren Konte
  • 306
  • 4
  • 12