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

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

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 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年前 评论

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