# 拦截检查

如果您曾经使用admin用户类构建了一个应用程序，那么您可能已经在本章中查看了所有简单的授权闭包，并考虑了如何在每种情况下添加一个覆盖这些检查的超级用户类。 值得庆幸的是，已经有了一个工具。

在AuthServiceProvider中，您已经定义了自己的能力，您还可以添加一个before()检查，该检查在所有其他功能之前运行，并且可以选择性地覆盖它们，如示例9-25所示。

{% code title="Example 9-25. Overriding Gate checks with before()" %}

```php
Gate::before(function ($user, $ability) { 
    if ($user->isOwner()) {
        return true; 
    }
});
```

{% endcode %}

注意能力的名字也被传入了，因此你可以用名字来区分before()钩子能力。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://liseen315.gitbook.io/laravel/yong-hu-ren-zheng-yu-shou-quan/shou-quan-acl-he-jiao-se-1/lan-jie-jian-cha.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
