You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB
PHTML

2 years ago
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Request;
2 years ago
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class AuthAdmin extends Middleware
{
/**
* Handle an incoming request.
*
* @param Request $request
2 years ago
* @param \Closure $next
* @param mixed ...$guards
2 years ago
* @return mixed
*/
public function handle($request, Closure $next, ...$guards)
{
if (auth()->check() && auth()->user()->type === 'Admin') {
return $next($request);
}
if ($request->ajax()) {
$errorCode = 403;
$result = [
"message" => '권한이 없습니다.',
"success" => false,
"data" => [],
"errors" => []
];
// logger(json_decode(json_encode($result), true));
$headers = [];
return response()->json($result, $errorCode, $headers, JSON_UNESCAPED_UNICODE);
} else {
$data = [
'exception' => new AccessDeniedHttpException()
];
return response()->view('errors', $data);
}
}
}