I want to destroy the session on all routes except certain I have created a middleware for this
public function handle(Request $request, Closure $next)
{
$currentRouteName = $request->route()->getName();
if ($currentRouteName !== 'wasteGenerationImpact.store' && $currentRouteName !== 'wasteGenerationImpact.index')
{
// Destroy the session when the condition is met
Session::forget(['reportingPeriodId', 'reportingPeriodName']);
}
return $next($request);
}
Route::prefix('wasteGenerationImpact')->name('wasteGenerationImpact.')->group(function () {
Route::get('/{wasteGenerationImpact?}', [WasteGenImpactController::class, 'index'])->name('index');
Route::get('/store', [WasteGenImpactController::class, 'store'])->name('store');
Route::post('/update/{id}', [WasteGenImpactController::class, 'update'])->name('update');
Route::get('/delete/{id}', [WasteGenImpactController::class, 'destroy'])->name('destroy');
Route::get('/restore/{id}', [WasteGenImpactController::class, 'restore'])->name('restore');
});
Session not destroying on index method but destroying on store.
I don’t want to destroy session when user is in wasteGenerationImpact’s routes