cms/app/Http/Middleware/AdminAreaGuard.php

36 lines
713 B
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Http\Middleware;
use Closure;
/**
* 判斷後台權限
*
* Class AdminAreaGuard
* @package App\Http\Middleware
*/
class AdminAreaGuard
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$user = $request->user();
if($user) {
if($user->can('admin area')) {
return $next($request);
} else {
abort(403); // 有登入但無權限
}
} else {
abort(404); // 無登入回應404顯示找不到頁面
}
}
}