
Display message with session flash using bootstrap alert class in laravel
Display message with session flash using bootstrap alert class in laravel
In this session, we’ll try our hand at solving the "Display message with session flash using bootstrap alert class in laravel" puzzle by using the computer language.
You can display alert messages in view files using the session flash in laravel 8. This code snippet helps you to add a bootstrap dynamic alert class (alert-success, alert-danger, alert-info) to show different types of messages for failures and success using session flash.-
Display alert message with session flash in laravel 8
//Import session facade in class use Illuminate\Support\Facades\Session; //Controller's method response after performing the task //Inside controller's method if(!$condition){ Session::flash('message', 'Error message !'); Session::flash('alert-class', 'alert-danger'); return redirect()->back(); } Session::flash('message', 'Success message !'); Session::flash('alert-class', 'alert-success'); return redirect()->back(); //Display message with dynamic alert class in view file @if(Session::has('message')) <div class="alert {{ Session::get('alert-class', 'alert-info') }} alert-dismissible fade show"> {{ Session::get('message') }} <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> @endif
This code snippet helps you to show messages with bootstrap alert in the view file which is returned by the controller using session flash in Laravel 8.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Json encode method in laravel
- Display first n record from collection in laravel view
- How to check duplicate entry in laravel
- The POST method is not supported for this route. Supported methods: PUT.
- How to get selected categories on edit record with Select2
- How to display order by null last in laravel
- PhpMyAdmin - Error The mysqli extension is missing
- Array to string conversion laravel Controller
- Insert current date time in a column using Laravel
- How to run a specific seeder class in laravel
- How to Access Array in blade laravel
- How to get random string in Laravel
- How to get date from created_at field in laravel
- In order to use the Auth::routes() method, please install the laravel/ui package
- How to increment column value of table in Laravel
- How to get data from two tables in laravel
- How to upload multiple images after preview in laravel using cropper js
- Call to a member function pluck() on array
- How to pass data to route in laravel?
- Call to undefined relationship [user] on model [App\Models\Post]
- OrderBy on Eloquent relationships method in Laravel
- How to customize pagination view in laravel
- Laravel route redirect not working
- How to check column value of a record is null or not in laravel
- Call to undefined method App\Models\User::follow()