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
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
While it uses the same syntax as view()->with()
, using with()
on a redirect doesn't work quite the same way. Your message will be stored as flash data and thus is in Session::get('msg')
, not $msg
.
Try this:
return Redirect::back()->withErrors(['msg', 'The Message']);
and inside your view call this:
@if($errors->any())
<h4>{{$errors->first()}}</h4>
@endif