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.
Related Queries
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
- Split an Eloquent Collection by half in Laravel
- RuntimeException You must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
- How to update record after save method in Laravel
- If condition in Laravel 9
- How to get query string value in laravel
- How to check query string exists or not in laravel blade
- How to create and run user seeder in laravel
- Laravel order by date not working
- How to add background image to div using Tailwindcss, Vite in Laravel Environment
- Multiple Level eager loading in Laravel
- How to get only time from created_at in laravel
- Laravel 9 route group with controller
- How to create belongstomany relation using custom name on custom pivot table
- Get current URL on visit URL in Laravel
- How to insert dynamic values to additional column with pivot column in pivot table on multiple records
- How to change default timestamp fields name in Laravel
- How to restore deleted records in laravel
- Class App\Http\Controllers\Admin\UserController Does Not Exist
- PhpMyAdmin - Error The mysqli extension is missing
- How to get IP address in laravel
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- How to create static page in Laravel
- Symlink(): No such file or directory
- Class "App\Http\Controllers\Auth\Verified" not found
- Call to a member function pluck() on null