Ad
My Sessions Flash Messages Are Not Working In Laravel
i am using FLASH in Laravel to display small notification here is how my function looks like:
public function movetotrash($id){
$page = Pages::where('id', $id) -> first();
$page -> active = 0;
//$page -> save();
\Session::flash('flash_message', 'Post has been successfully moved to trash');
return redirect('pages');
}
Here is how my View looks like:
<div class="col-md-12">
@if(Session::has('flash_message'))
<div class="alert alert-success">
{{Session::get('flash_message')}}
</div>
@endif
</div>
And here is how my Route looks like:
Route::get('/', function () {
return view('welcome');
});
Route::get('dashboard', function () {
return view('dashboard.dashboard');
});
Route::get('pages/trash', '[email protected]');
Route::get('pages/movetotrash/{id}', '[email protected]');
Route::resource('pages', 'PagesController');
Do i need to call some library in my controller for Session
to work?
Thank you! (in advance)
Ad
Answer
From laravel docs : https://laravel.com/docs/master/routing
Any routes not placed within the web middleware group will not have access to sessions and CSRF protection, so make sure any routes that need these features are placed within the group. Typically, you will place most of your routes within this group:
Route::group(['middleware' => ['web']], function () {
//all routes
});
Put your routes inside middleware and your problem will solve.
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad