Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

481
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda