Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

480
Views
Laravel - LoginController | How to set $redirectTo route with parameters?

In my LoginController I have defined a custom redirect route like this:

protected $redirectTo = '/home';

which works fine but I want to show a toastr notification when user logs in therefore I want to flash some data with this redirect.

In my other controllers I'm doing something like this and it works good

$notification = array(
                        'message' => 'User okay', 
                        'alert_type' => 'success',
                      );
return Redirect::route('user')->with('notification', $notification);

but I can't figure out how to it with the $redirectTo

Please help me with this

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

One way to pass a "message bag", is to create a redirectTo method in the LoginController.

Out of the box this method is not present, because it is inherited from the trait RedirectsUsers so, just wrote it and complete as needed and it will be executed just when the user had been authenticated (as the function name say)

protected function redirectTo(Request $request)
{
    $notification = array(
        'message' => 'User okay', 
        'alert_type' => 'success',
    );
    return Redirect::route($this->redirectTo)->with('notification', $notification);
}

As you can see, the trait RedirectsUsers is looking for a defined redirectTo function or using the variable you define as $redirectTo

public function redirectPath()
{
    if (method_exists($this, 'redirectTo')) {
        return $this->redirectTo();
    }

    return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
}

Otherwise, if the parameters you would like to pass is a simple GET parameter, you can use the same authenticated function and set it with the parameters as you prefer, also dynamic params like

protected function redirectTo(Request $request)
{
    return redirect()->route('route.name', [param1 => value1, param2 => value2]);
}

For the redirect purpose this is more clear then using other functions like the "authenticated" ones suggested before.

over 4 years ago · Santiago Trujillo Report

0

you can set a method redirectTo() with your custom logic in your LoginController. That method will be called first in redirectPath() from trait RedirectsUsers.

hope it helps CV

over 4 years ago · Santiago Trujillo Report

0

simply you can do with get params, /home?your_data='blabla'&another_data='blabla' and after that use that params in controller to show in view. But in laravel you can do this more pretty;

Route('home{notification?}','YourController@yourAction');

and in YourController you shoud do

public function yourAction($notification = null) {
   if(isset($notification) {
//do something with notification
}
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!