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
- Class 'App\Providers\Auth' not found
- How to add active class to menu item in laravel
- Laravel delete all rows older than 30 days
- Php artisan make model, factory, migration and controller in single command
- Return view from route Laravel
- How to validate URL with https using regex in laravel
- Call to undefined relationship [user] on model [App\Models\Post]
- Method Illuminate\Events\Dispatcher::fire does not exist
- Recursive function example code PHP Laravel
- Extract only time from datetime in laravel
- File_put_contents(/var/www/html/w3code/storage/framework/sessions/CXwN3EXKxERD6jgy3rADcaAAbAx8FRKih2JK7UO9): Failed to open stream: Permission denied
- Laravel upload file with original file name
- Create user in Laravel using tinker
- Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement
- How to implement toggleLike() method in Overtrue\LaravelLike laravel package
- How to include header file in laravel
- How to use or operator in laravel
- Sample .htaccess file and index.php file under public directory in laravel
- How to create and run user seeder in laravel
- How to delete record in Laravel with ajax
- How to customize or Change validation error messages
- Seed database using SQL file in Laravel
- Generate unique username in Laravel
- Return redirect laravel not working
- How to pass data to multiple partial view files in laravel