Skip to content

Instantly share code, notes, and snippets.

@ydenissov
Created October 30, 2022 18:25
Show Gist options
  • Save ydenissov/fb60363d7b0b83faca7031eb50b96447 to your computer and use it in GitHub Desktop.
Save ydenissov/fb60363d7b0b83faca7031eb50b96447 to your computer and use it in GitHub Desktop.
Middleware for check user Active
<?php
/* Add in Http\Kernel.php after protected $routeMiddleware -> 'isActive' => \App\Http\Middleware\CheckUserActive::class, */
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Auth;
class CheckUserActive
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Auth::check()) {
if ($request->user()->blocked === 1) {
Auth::logout();
return redirect()->to('login')->withErrors(Lang::get('auth.blocked'));
}
}
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment