Ad

Laravel Doesn't Display Massage While Redirecting Back

- 1 answer

in my controller i have

//some actions
return redirect()->back()->with("msg", "ტური შენახულია");

in my blade template i have

    @if(isset($msg))
        <div class="alert alert-success"><strong>{{$msg}}</strong></div>
    @endif

but it doesnt display the massage. i also try this

return redirect()->back()->with(["msg", "ტური შენახულია"]);



$msg = "ტური შენახულია";
return redirect()->back()->with(compact("msg"));

but it doesnt display anyway

Ad

Answer

When you use with() in conjunction with a redirect, it does not place that variable inside the view, it simply flashes that data to the session.

So to grab it from your view, you will need to use session('msg'). Keep in mind that will only be available for this response so you will likely want to make sure it exists before trying to display it.

Can read more at https://laravel.com/docs/5.2/responses#redirects

Ad
source: stackoverflow.com
Ad