Reputation: 2655
What is a good practice on handling localised messages in Laravel?
For example; 'You have successfully added the user'.
Should I redirect the user to a page which is like /user/success
or would it be better to do something like /user?message=success
.
Any feedback would be appreciated!
Upvotes: 0
Views: 123
Reputation: 724
I prefer flash message, then on the view you can even get a timeout for the message to make it look really good. Now this approach works for me. On controller side :
if($result==1)
{
Session::flash('message', 'You have successfully added the user');
return Redirect::to('/user/success');
}
else{
Session::flash('message', 'Something went wrong.');
return Redirect::to('/user/error');
}
Now at view side its simple.
@if (Session::has('message'))
<div class="alert alert-info" id="hider">
{{ Session::get('message') }}
</div>
@endif
Now you can use jquery or noty to display and auto-hide the message block
Upvotes: 2
Reputation: 2862
Redirect user to /page/success
with the message You have successfully added the user
or anything else is more flexible. Example, if the user successful add item to cart, it will also redirect to /page/success
with another message (just the different message, not the action).
Upvotes: 1