Laravel 5.2 redirect back with success message

前端 未结 9 2174
忘掉有多难
忘掉有多难 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:30

    You can simply use back() function to redirect no need to use redirect()->back() make sure you are using 5.2 or greater than 5.2 version.

    You can replace your code to below code.

    return back()->with('message', 'WORKS!');
    

    In the view file replace below code.

    @if(session()->has('message'))
        
    {{ session()->get('message') }}
    @endif

    For more detail, you can read here

    back() is just a helper function. It's doing the same thing as redirect()->back()

提交回复
热议问题