Reputation: 207
I have profile form with fields, that use should fill.
After submit button I do redirect to another controller(page).
How can I show message there only once? I mean that if user will update again profile, message will not showen more.
Upvotes: 0
Views: 2476
Reputation: 357
Try this, it will only show message one time:
if($user_update) {
if(Session::has('update_profile_message') {
return redirect()->back(); //or wherever you want to redirect
} else {
return redirect()->back()->with('update_profile_message', 'Your profile has been updated successfully.');
}
}
Upvotes: 1
Reputation: 417
You just need to redirect with flashing session data. For example, In your routes file, you may have this:
Route::post('user/profile', function () {
// Update the user's profile...
return redirect('dashboard')->with('status', 'Profile updated!');
});
In your blade file, check and show the 'message' stored in sessions
@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif
For more info, visit https://laravel.com/docs/5.3/redirects#redirecting-with-flashed-session-data
Upvotes: 0
Reputation: 3422
Your function:
public function deleteObject($ho_id) {
return redirect()->back()->with('message', 'My message.'); //return back and set a session key, message
}
Your code (layout that you want to extend)
@if (Session::has('message'))<!-- check if hash message key in session -->
<div class="callout callout-info">
<h4>
Message
</h4>
<p>{{ Session::get('message') }}</p><!-- show the message -->
</div>
@endif
Hope this works!
Upvotes: 0