25
common/Core/Middleware/IsAdmin.php
Executable file
25
common/Core/Middleware/IsAdmin.php
Executable file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Common\Core\Middleware;
|
||||
|
||||
use Auth;
|
||||
use Closure;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class IsAdmin
|
||||
{
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
if ( ! Auth::check()) {
|
||||
throw new AuthenticationException();
|
||||
}
|
||||
|
||||
if ( ! Auth::user()->hasPermission('admin')) {
|
||||
throw new AuthorizationException();
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user