
Session Doesn't Work on Redirect
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.
Answers 1
-
//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
1
Random Code Snippet Queries: Laravel
- How to get count of all records created at yesterday
- Get current month records in laravel 7/8
- How to get all route list
- Laravel save object to database
- PhpMyAdmin - Error The mysqli extension is missing
- How to get single column value in laravel
- Get last record from table in laravel
- Method Illuminate\Database\Eloquent\Collection::lists does not exist
- Method Illuminate\Events\Dispatcher::fire does not exist
- Attempt to read property "avatar" on null in Laravel
- Call to a member function update() on null
- How to validate URL with https using regex in laravel
- Class "App\Http\Controllers\Auth\Verified" not found
- Laravel create default admin user
- Create a record if not exist in laravel
- Laravel insert query not working
- How to validate website url in laravel using validaiton
- Run artisan command to generate key in laravel
- How to insert dynamic values to additional column with pivot column in pivot table on multiple records
- Method Illuminate\Http\Request::validated does not exist
- On delete set foreign id column value null using migration in laravel 8
- After image selected get validation error in laravel
- Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request
- RuntimeException You must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
- Store logged in user details in session and display in view in laravel