Laravel display flash message on view : Session::get(‘message_key’) is used to get the flash message in laravel. In any framework flash messages play a key role to display the messages which makes the error message handling and other messages very easy. In this tutorial we are going to explain how you can handle the flash messages in laravel and display them on view.
Laravel display flash message on view
You can set and get the flash messages as below-
Laravel set flash message : Controller
Laravel display flash message on view:
.. public function myFunction(){ // your code goes here .. Session::flash('success', "Data updated successfully."); } |
The above example will set the flash message in the above controller. Now let us display this flash message on the view file.
Laravel display flash message : View
Laravel display flash message on view:
@if(Session::has('success')) {{ Session::get('success') }} @endif |
The above example will check the flash message and if it has some flash message then it will display on the view file.