
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
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.post_id' in 'where clause
- How to get file extension from input type file in laravel
- Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given
- Get last week data in Laravel
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- Method Illuminate\Http\Request::validated does not exist
- How to get user information using hootlex/laravel-friendships package in laravel
- Check if Relationship Method Exists in Laravel
- Get all users except the followings users in overtrue laravel-follow
- Calculate age from date of birth in Laravel
- How to restore deleted records in laravel
- How to get images from AWS s3 and display in Laravel blade
- Update existing pivot table data in laravel
- How to check duplicate entry in laravel
- Class "App\Http\Controllers\Auth\Verified" not found
- How to insert dynamic value to additional column in pivot table in laravel
- Get last year created records in Laravel
- Get ids in array from users table
- Get today records in Laravel
- Use withCount() to get total number of records with relationship
- Remove public from url in laravel project
- How to create static page in Laravel
- Get 30 days older records from table in laravel
- Method Illuminate\Database\Eloquent\Collection::lists does not exist
- JQuery each loop on json response after ajax in laravel