Reputation: 3925
I have a route post called "postContact" and when the post is success I redirect to the same contact.blade.php where place the post:
<form action="{{ route('post_contact) }}"></form>
I want to see a msg if the post have success, but the Input::get('some data') not working to me.
this is my controller resume:
public function postContact($params) {
//if successful
$msg_params = array(
'msg_type' => 'success',
'msg_text' => 'my text to show',
);
return redirect()->back()->withInput($msg_params);
}
But in the contact.blade.php this not working:
@if(isset($msg_type))
<div class="alert">{{ $msg_text }}</div>
@endif
The variables not exits...
I don´t want use flash data here, because contact.blade is a module of another external app laravel and can't share sessions.
What is happening here?
Upvotes: 2
Views: 3719
Reputation: 11257
Controller
return redirect()->back()->with('success', ['your message,here']);
Blade:
@if (\Session::has('success'))
<div class="alert alert-success">
<ul>
<li>{!! \Session::get('success') !!}</li>
</ul>
</div>
@endif
Upvotes: 0
Reputation: 24276
Because doing a redirect, those variables are set in session. So you may try:
@if(Session::has('msg_type'))
<div class="alert">{{ Session::get('msg_text') }}</div>
@endif
If you don't want to use session variables, then you can use route parameters. You can get the parameters using the Request
facade:
@if(Request::has('msg_type'))
<div class="alert">{{ Request::get('msg_text') }}</div>
@endif
Upvotes: 1
Reputation: 3422
If you're redirecting back to the page, Laravel will store the data in the Session. So you need to enter this to show the data:
@if(Session::has('msg_type'))
<div class="alert">
{{ Session::get('msg_text') }}
</div>
@endif
Hope this works!
Upvotes: 1