Since I updated my Laravel version to 7.4, the session flash messages stopped working in Views.
Here is what a part of my code looks like: Web.php
Route::middleware(['web'])->group(function () {
Route::middleware(['permission:super_user'])->group(function () {
Route::get('/get/{id}', 'TestController@show');
Route::post('/set/{id}', 'TestController@update');
});
});
Controller Methods:
public function update(Request $request, $id){
$message = new stdClass();
$message->type = 'success';
$message->text = "Updated successfully!" ;
session()->flash('message', $message);
return Redirect::back();
}
public function show(Request $request, $id){
return view('pages.account')
}
Session data is there but flash messages are getting lost somewhere between redirection, not sure where exactly. I tried several solutions like session reflash, removing the web from middleware but it didn't work. Any leads?
Edit: I found out that session flash exist in this method. Which means app redirect erasing it?
function back($status = 302, $headers = [], $fallback = false)
{
dd(session());
return app('redirect')->back($status, $headers, $fallback);
}
Try this solution. In controller method:
public function update(Request $request, $id){
$message = new stdClass();
return redirect()->back()->with('success', 'Updated successfully!');
}
In blade file do this:
@if(session()->has('success'))
<div class="alert alert-success text-center">
{{ session()->get('success') }}
</div>
@endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With