我做了一个自定义保护实现,强制禁用"记住我"。撇开这个自定义实现的细节不谈 - 当我尝试将其绑定到 Guard 合约时,似乎出了点问题。
Customguard.php
<?php
namespace App'Contracts'Auth;
use Illuminate'Auth'Guard as StockGuard;
use Illuminate'Contracts'Auth'Authenticatable as UserContract;
use Illuminate'Contracts'Auth'Guard as GuardContract;
class CustomGuard extends StockGuard implements GuardContract
{
/**
* Log a user into the application.
*
* @param 'Illuminate'Contracts'Auth'Authenticatable $user
* @param bool $remember
* @return void
*/
public function login (UserContract $user, $remember = false)
{
parent::login($user, false);
}
}
(Guard->login
被完全相同的方法签名覆盖)
我按照boot
方法进行了如下绑定app/Providers/AuthServiceProvider.php
$this->app->bind('Illuminate'Contracts'Auth'Guard', App'Contracts'Auth'CustomGuard::class);
一切都在调用自定义卫士>登录之前一直有效。
BindingResolutionException in Container.php line 749:
Target [Illuminate'Contracts'Auth'UserProvider] is not instantiable.
我做错了什么?
Userprovider 是一个接口,你必须使用实现接口的类,我认为这就是 eloquente Userprovidev。
改变:
use Illuminate'Contracts'Auth'UserProvider;
自:
use App'Http'Controllers'Auth'CustomUserProvider as UserProvider;