
Session Doesn't Work on Redirect
Created at 08-Mar-2022 ,
By samar
Trying to display the error and success message in blade file after redirect using session in Laravel. In my case Session doesn't wok on redirect.
-
//Import session facade use Illuminate\Support\Facades\Session; //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(); //Blade view @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
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
- Laravel clone model
- Extract only time from datetime in laravel
- Laravel delete all rows older than 30 days
- Laravel route redirect not working
- Get content from web URL in laravel
- File_put_contents(/var/www/html/w3code/storage/framework/sessions/CXwN3EXKxERD6jgy3rADcaAAbAx8FRKih2JK7UO9): Failed to open stream: Permission denied
- How to get data from two tables in laravel
- Get only 10 records from table in laravel
- Php artisan make model, factory, migration and controller in single command
- Import/Use Storage facade in laravel
- Convert input array to comma-separated string in laravel controller
- How to create belongstomany relation using custom name on custom pivot table
- Laravel onclick function not working
- Class App\Http\Controllers\Admin\UserController Does Not Exist
- How to get last year records count with month wise in Laravel
- Insert values in pivot table dynamically in laravel
- Target class [HomeController] does not exist
- How to use bootstrap pagination in laravel 8
- How to pass external link in laravel blade to anchor tag
- How to get selected categories on edit record with Select2
- How to start websocket server in laravel
- Composer create project laravel/laravel example app
- Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused)"
- Credit card validation in laravel
- PhpMyAdmin - Error The mysqli extension is missing