Laravel prevent browser back button after logout

  Fri 05 / 05 / 2023

  Posted by: Mariya khan

Category : Laravel

Tags : laravel , php laravel , backend

Description

Laravel Prevent Browser Back Button After Logout " jb logout krden to back button se dashboard p na jaye bal k login p ayee " mne ise middleware se kia h but kaam nh kar rha r middle ware k function m date and time knsa mention karna h wo smjh nh ara "


View Code
                        middleware code :
public function handle(Request $request, Closure $next)
    {
        $response=$next($request);
        $response->header('Cache-Control','nocache, no-store, max-age=0, must-revalidate')
        ->header('Pragma','no-cache')
        // ->header('Expires','Sat, 26 Jul 1997 05:00:00 GMT');
        ->header('Expires','Sun, 02 Jan 1990 00:00:00 GMT');
        return $response; 
    }



after this i registered middleware in kernal :
'Disable_Back_Btn' => \App\Http\Middleware\DisableBackBtn::class,



after this i apply middleware in route:
Route::group(['middleware' => 'Disable_Back_Btn'],function(){
Route::get('/dashboard', [SuperAdminController::class, 'dashboard'])->name('dashboard');
});


i apply it on the dashbaord route because i dont want to redirect after logout on dasboard 



please help urgent
                
  Answered by CDL

@Maria agr ap button se logout krana chahti hai to simple facade se check kr lein k user login ni hai to usey login pe bhej dey otherwise dashboard visit kr ley.

solution

~~~

public function handle(Request $request, Closure $next)

{

  if (! auth()->check()) {

   return redirect()->route('login');

  }


  return $next($request);

}

~~~

  Comment   Share
0 Likes   0 Comments