讨论数量:
从 Gate、策略 返回授权响应时,gate::allows 方法仍将返回一个简单的布尔值。但是可以使用 gate::inspect 方法获取 Gate 返回的完整授权响应
$response = Gate::inspect('update', $post);
if ($response->allowed()) {
// The action is authorized...
} else {
echo $response->message();
}
App\Exceptions\Handler.php
public function render($request, Throwable $exception)
{
if ($exception instanceof AuthenticationException) {
// 此处自定义返回response对象
}
}
推荐文章: