为什么在这个“添加自定义提供程序”教程之后,我在我的Laravel项目中找不到“App \ Extensions \ RiakUserProvider”命名空间?
我是绝对新来的PHP和Laravel。为什么在这个“添加自定义提供程序”教程之后,我在我的Laravel项目中找不到“App Extensions RiakUserProvider”命名空间?
我工作的一个Laravel 5.3应用程序,我不得不使用定制的Web服务来检查用户凭据,所以我试图按照这个官方教程的添加自定义提供处理用户访问:https://laravel.com/docs/5.3/authentication#adding-custom-user-providers 。所以,从理论上讲,这似乎很简单,但我发现一些困难。
正如您在前一个教程中所看到的那样,它将修改Laravel项目中包含的类别App \ Providers \ AuthServiceProvider。
所以,我根据教程的例子获得修改我的AuthServiceProvider这样的:
<?php namespace App\Providers; 
use Illuminate\Support\Facades\Gate; 
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; 
use Illuminate\Support\Facades\Auth; 
use App\Extensions\RiakUserProvider; 
use Illuminate\Support\ServiceProvider; 
class AuthServiceProvider extends ServiceProvider 
{ 
    /** 
    * The policy mappings for the application. 
    * 
    * @var array 
    */ 
    protected $policies = [ 
     'App\Model' => 'App\Policies\ModelPolicy', 
    ]; 
    /** 
    * Register any authentication/authorization services. 
    * 
    * @return void 
    */ 
    public function boot() 
    { 
     $this->registerPolicies(); 
     // CUSTOM CODE: 
     Auth::provider('riak', function ($app, array $config) { 
      // Return an instance of Illuminate\Contracts\Auth\UserProvider... 
      return new RiakUserProvider($app->make('riak.connection')); 
     }); 
    } 
} 
的问题是,它无法找到应用程序\扩展命名空间中,这样的:
use App\Extensions\RiakUserProvider; PhpStorm标志公司名称红色标注“Undefined Extensions namespace”所以它不能在我的代码中使用RiakUserProvider类。
为什么?我必须在Composer中添加一些依赖项吗?哪里不对?我错过了什么?我该如何解决这个问题?
究竟是什么RiakUserProvider类?
这究竟代码:
Auth::provider('riak', function ($app, array $config) {     // Return an instance of Illuminate\Contracts\Auth\UserProvider... 
    return new RiakUserProvider($app->make('riak.connection')); 
}); 
回答:
在Laravel文档的RiakUserProvider类仅仅是一个例子定制的用户提供。类位于App\Extensions名称空间中,但未提供实际提供者类的内容。
如果你想创建一个自定义用户提供,你应该在你的文件夹App创建一个名为Extensions文件夹,并创建RiakUserProvider.php文件,其中包含RiakUserProvider类。这遵循PSR-4类自动加载标准。
当你创建你自己的用户提供者时,请确保它实现了Illuminate\Contracts\Auth\UserProvider接口。
这里是一个很好的教程一步一步创建一个:
https://blog.georgebuckingham.com/laravel-52-auth-custom-user-providers-drivers/
以上是 为什么在这个“添加自定义提供程序”教程之后,我在我的Laravel项目中找不到“App \ Extensions \ RiakUserProvider”命名空间? 的全部内容, 来源链接: utcz.com/qa/258308.html







