I am working on a project in which I am using flash session after form submit to display the message. But the problem is that the flash session message sometimes appears and sometime not.I know this issue mostly occurs when web middleware is applied twice. I did not apply web middleware twice. It's applied automatically. I shared the code also here.
`public function edit_department(Request $req,$id){
$dep = department::where("externalid", $id)->first();
if($req->method() == "POST")
{
$req->validate([
'inst'=>'nullable|max:2999',
'name'=>'required|min:3|max:60',
]);
try
{
$dep->name = $req->name;
$dep->inst= $req->inst;
if($dep->save())
{
dispatch(
function () use ($this>users)
{
$this->sendMail($this->users);
}
)->delay(now()->addSeconds(3);
return redirect()->back()->with(['bool' => 'true', 'message' => 'Department Updated ']);
}
else
{
return redirect()->back()->with(['bool' => '1', 'message' => 'Nothing was changed']);
}
}
else
{
return redirect()->back()->with(['bool' => '0', 'message' => 'Department not edit ']);
}
}
return view("departments.update_department");
}`
In blade:
@if(Session::has("bool")) @if(session("bool") == "1") {!! session("message") !!} @elseif(session("bool") == "0") {!! session("message") !!} @endif @endif
Route:
Route::match(['get','post'],'edit_department/{id}',[DepartmentController::class,"edit_department"])->name("edit_department");
This is one function I have given. But the same situation occurs for all the function that flash session message sometime appears and sometime not.
What and where can be the problem. Anyone?