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
- Display first n record from collection in laravel view
- How to include header file in laravel
- Store logged in user details in session and display in view in laravel
- How to get route method name in Laravel
- Get 30 days older records from table in laravel
- Laravel save object to database
- Laravel create default admin user
- Run artisan command to generate key in laravel
- How to Access Array in blade laravel
- How to create project_user pivot table in laravel
- Method Illuminate\Http\Request::validated does not exist
- Laravel specific table Migration
- Laravel create multiple records in Pivot table
- Call to a member function pluck() on null
- How to pass link from controller to view in laravel on ajax call
- Permanently delete a record in laravel
- Pagination in laravel
- How to check if user has created any post or not in laravel
- Insert values in pivot table dynamically in laravel
- After image selected get validation error in laravel
- How to get last record from object collection in laravel
- How to send email in Laravel 11
- Get last week data in Laravel
- How to return error message from controller to view in laravel
- The POST method is not supported for this route. Supported methods: PUT.