
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
- Add a subselect based on relationship using withAggregate method
- Get domain name in laravel
- How to get session in blade Laravel ?
- Laravel 5.4 save data to database
- Retrieve count of nested relationship data in Laravel
- How to implement toggleLike() method in Overtrue\LaravelLike laravel package
- Delete file from amazon s3 bucket using Laravel
- How to pass variable from controller to model in Laravel
- How to get the id of last record from collection object in laravel view
- Get the products list ordered by a user
- How to get last year records count with month wise in Laravel
- Display option of select as selected with blade directive Laravel
- Insert Comma Separated Values in laravel
- Laravel route redirect not working
- Split an Eloquent Collection by half in Laravel
- How to get all route list
- Where to use whereNotNull eloquent in laravel
- How to check relationship is loaded or not in Laravel
- Get current URL on visit URL in Laravel
- How to get specific columns using with method in laravel Eloquent relationship
- Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given
- Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused)"
- How to Run CRON Job on LIVE SERVER on Cpanel in Laravel Project
- Get duplicate records in laravel
- How to add class to tr in table using foreach in laravel