Redirect and Route on Laravel 5.5, is it possible?

Asked

Viewed 638 times

1

I’m having a beginner’s difficulty here in my training with Laravel 5.5 I just created an update method - Update,

public function atualizar(Request $request, $id)
{
    $dados = $request->all();

    if(isset($dados['situacao']))
    {
        $dados['situacao'] = "Ativa";
    }
    else
    {
        $dados['situacao'] = "Inativa";
    }

    Empresa::find($id)->update($dados);

    $mensagem = "Empresa altera com sucesso!";
    return redirect()->route('admin.empresas')->with('mensagem', $mensagem);
}

The update is being performed correctly, but the message is not being returned to the screen for an Alert. This redirect that I’m using is not correct?

Thanks.

  • how you’re doing in the view?

  • 1

    Thus Virgilio: @if (session('mensagem'))&#xA; <div class="alert alert-success" role="alert">{{$mensagem}}</div>&#xA;@endif

  • do so: @if (Session::has('mensagem')) <div class="alert alert-success" role="alert">{{session('mensagem')}}</div> @endif !!!

  • It didn’t work, message didn’t show up

  • does so now in the method return redirect(route('admin.empresas'))->with('mensagem', $mensagem); I’m in the bank kkk

  • I just got back here, it didn’t work out either. :(

  • Put your View!

  • I put in my doubt, look there

  • First look at my comment, and then tell me does not appear the text? or nothing appears? the Box appears?

  • Virgilio I’m sorry, the wrong code, it was not in the form that the message should appear, but in a list.

  • Then following your Return tip, I had to do the following to get it right @if (Session::has('mensagem'))&#xA; <div class="alert alert-success" role="alert">{{Session::get('mensagem')}}</div>&#xA; @endif

  • worked out ?....

  • Simmm, thanks for your help

Show 8 more comments

1 answer

1

After several messages were exchanged with @Virgilio, I decided as follows:

In control I put the following return:

return redirect()->route('admin.empresas')->with('mensagem', $mensagem);

Already in View, I performed the following check:

@if (Session::has('mensagem'))
   <div class="alert alert-success" role="alert">{{Session::get('mensagem')}</div>
@endif

Browser other questions tagged

You are not signed in. Login or sign up in order to post.