[英]Laravel can't create custom UserProvider Class not found
I'm trying to create a custom auth provider in laravel.我正在尝试在 laravel 中创建一个自定义身份验证提供程序。 I already added a new provider in the config/auth.php
and also created a Class that implements Illuminate\\Contracts\\Auth\\UserProvider
.我已经在config/auth.php
添加了一个新的提供者,并且还创建了一个实现Illuminate\\Contracts\\Auth\\UserProvider
。
But when I try to add the Class as a provider in the AuthServiceProvider
it says Class 'App\\Extensions\\CustomProvider' not found
.但是,当我尝试将 Class 添加为AuthServiceProvider
的提供程序时,它显示Class 'App\\Extensions\\CustomProvider' not found
。 But when I remove implements UserProvider
in my Class it returns ...must be an instance of Illuminate\\Contracts\\Auth\\UserProvider
.但是当我在我的类中删除implements UserProvider
,它返回...must be an instance of Illuminate\\Contracts\\Auth\\UserProvider
。
My Code to create the provider:我创建提供程序的代码:
Auth::provider('customProvider', function($app, array $config) {
return new CustomProvider($app->make('request'));
});
The documentation doesn't show the class itself. 文档没有显示类本身。
Edit: Here my custom provider:编辑:这里是我的自定义提供程序:
namespace App\Extensions;
use Illuminate\Contracts\Auth\UserProvider;
class CustomProvider implements UserProvider
{
protected $request;
public function __construct(Request $request) {
$this->request = $request;
}
// Here the functions from the interface
// ...
}
You forgot a use
statement, so it thinks the interface is in your own namespace.您忘记了use
语句,因此它认为该接口在您自己的命名空间中。
Easily fixed.很容易固定。
use Illuminate\\Contracts\\Auth\\UserProvider;
Then implement it again and it will work!然后再次实施它,它会起作用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.