Laravel 5.2 redirect back with success message

前端 未结 9 2194
忘掉有多难
忘掉有多难 2020-12-13 01:50

I\'m trying to get a success message back to my home page on laravel.

return redirect()->back()->withSuccess(\'IT WORKS!\');

For some

9条回答
  •  难免孤独
    2020-12-13 02:09

    One way to do that is sending the message in the session like this:

    Controller:

    return redirect()->back()->with('success', 'IT WORKS!');
    

    View:

    @if (session()->has('success'))
        

    {{ session('success') }}

    @endif

    And other way to do that is just creating the session and put the text in the view directly:

    Controller:

    return redirect()->back()->with('success', true);
    

    View:

    @if (session()->has('success'))
        

    IT WORKS!

    @endif

    You can check the full documentation here: Redirecting With Flashed Session Data

    I hope it is very helpful, regards.

提交回复
热议问题