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

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

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
讨论数量: 4

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

6年前 评论

这个地方引用 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 希望大神解惑。

6年前 评论

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