AuthServiceProvider.php 中没有添加 use Illuminate\Contracts\Auth\Access\Gate as GateContract;怎么理解这个

没添加报错,AuthServiceProvider.php并没有添加
ReflectionException
Class App\Providers\GateContract does not exist

《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 4

file
AuthServiceProvider.php 中有添加use,用于引用Illuminate\Contracts\Auth\Access\Gate目录下的文件,而as是作为这个文件的别名存在的,方便下面的调用。

5年前 评论

这个地方引用 Gate 接口,我也没看懂主要是做什么用。

use Illuminate\Contracts\Auth\Access\Gate as GateContract;
.
.
.
/**
     * Register any application authentication / authorization services.
     *
     * @param  \Illuminate\Contracts\Auth\Access\Gate  $gate
     * @return void
     */
    public function boot(GateContract $gate)
    {
        $this->registerPolicies($gate);

        //
    }

$this->registerPolicies($gate); 追踪到 registerPolicies 方法没有入参:

/**
     * Register the application's policies.
     *
     * @return void
     */
    public function registerPolicies()
    {
        foreach ($this->policies as $key => $value) {
            Gate::policy($key, $value);
        }
    }

我试着不引用 Gate ,boot 方法保留原样,发现也没问题。

public function boot()
    {
        $this->registerPolicies();

        //
    }

@Summer 希望大神解惑。

5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!