kunal kunal - 7 months ago 39
PHP Question

Delete session in laravel5.2 when cms pages accessed

I am new in laravel framework. Can anyone tell me how to delete sessions when cms pages accessed i.e(faq,privacy policy,about us). This query runs fine for me:-


The problem is that when i accessed the faq page i have write this query and when i accessed the privacy policy then again i have to write this query. Can anyone tell me how i do in one function. So i have not implement this query again and again

Thanks in advance :)


Create One middleware named as forgetSession(you can have any name) and set the cms pages route group in app\Http\routes.php under that middleware for eg.

Route::group(['middleware' => ['forgetSession']], function () {
    Route::resource('faq', 'faqController');
    Route::resource('privacy', 'privacyController');//likewise

Now create middleware by writing below command on cmd project root

php artisan make:middleware forgetSession

So it will create the middleware in app/Http/middleware/forrgetSession and put your code


So in this way all route mentioned under route group will have the code to forget session. This way definitely you can redundant the code.