How to show Save success message in Laravel 5.1?
Stefan Izdrail
Founder & Senior Architect · 2026-06-29
In your Laravel 5.1 application, you have successfully saved data to the database using the Controller's store method as shown above. Now let's discuss how to display a success message when saving data is successful. There are multiple ways of accomplishing this and we will cover them briefly.
Using Session Messages
Laravel offers an extremely convenient way to handle messages, either for success or errors, using the session messages feature. To display a success message when saving data in Laravel 5.1, you can simply add this code immediately after calling the save() method:
Session::flash('success', 'Seeder successfully saved!');
This will store the specified success message ("Seeder successfully saved!") in the session and show it next time a view is rendered. You can display this flash message from the views using the following code:
{{ Session::get('success') }}
Using Messages in Blade Templates
Alternatively, you can define messages directly within your view templates as shown below:
@if (Session::has('success'))
{{ Session::get('success') }}
@endif
Using Validation Messages
Another approach is to include validation messages in your Laravel 5.1 application. These messages can be used both for error and success notifications. To display a custom save success message, you can follow these steps:
1. In your controller, define an array of validation rules and a custom message for each field.$messages = [
'name' => 'The name field should be unique and not blank.',
'address' => 'The address cannot be empty.',
'age' => 'Please enter your age.',
];
2. Define a custom validation rule for the save() method in the controller.
$this->validate($request,[
'name'=>'required|unique:seeders|max:255',
'address'=>'required',
'age'=>'required',
], $messages);
3. Add the following code after calling save() in your controller to display validation messages:
if ($validator->fails()) {
return redirect()->back()->withErrors($validator)->withInput();
}
This approach will show error messages for invalid fields and a success message upon successful validation. Remember to include error messages in your views using the following code:
@if ($errors->any())
@foreach ($errors->all() as $error)
{{ $error }}
@endforeach
@endif
In conclusion, there are multiple ways to display success messages upon saving data in Laravel 5.1 applications. The choice depends on your preferences and project requirements. Be sure to consider the pros and cons of each approach and select the one that best fits your needs. For more guidance and practical examples related to Laravel development, visit https://laravelcompany.com.