
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
- How to create new user without form submission in laravel
- Display data in table using foreach in Laravel
- Update last created record in Laravel
- Session Doesn't Work on Redirect
- Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
- SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'posts_user_id_foreign'; check that column/key exists
- Use withCount() to Calculate Child Relationship Records
- Get Array of IDs from Eloquent Collection
- Non-static method App\Http\Helper::myFunction() should not be called statically
- Laravel hasmany select not working
- How to check data inserted or deleted in pivot after toggle method
- Get last year created records in Laravel
- How to customize or Change validation error messages
- Fatal error: Uncaught Error: Class "Illuminate\Foundation\Application" not found
- Laravel order by date not working
- Property [user] does not exist on this collection instance
- Recursive function example code PHP Laravel
- Method Illuminate\Database\Eloquent\Collection::appends does not exist
- Global scope in Laravel with example
- Retain selected value of select box in Laravel
- How to upload files to amazon s3 bucket using Laravel
- Eager loading dynamically in laravel
- Laravel insert query not working
- How to call model in blade laravel
- Send OTP using textlocal api in laravel