Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

483
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda