我正在开发 laravel 5.4 应用程序。 我有自定义用户类和自定义用户提供程序。
应用程序工作正常。 但是当我执行以下命令时:composer install --no-dev --optimize-autoloader
我收到以下错误:
vagrant@my-api:~/Code/my-api$ composer install --no-dev
--optimize-autoloader Loading composer repositories with package information Installing dependencies from lock file Nothing to install or update Generating optimized autoload files
> IlluminateFoundationComposerScripts::postInstall
> php artisan optimize PHP Fatal error: Uncaught InvalidArgumentException: Authentication user provider [external-user] is not defined. in /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/CreatesUserProviders.php:40 Stack trace:
#0 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(123): IlluminateAuthAuthManager->createUserProvider('users')
#1 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(96): IlluminateAuthAuthManager->createSessionDriver('web', Array)
#2 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(70): IlluminateAuthAuthManager->resolve('web')
#3 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(294): IlluminateAuthAuthManager->guard()
#4 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): IlluminateAuthAuthManager->__call('check', Array)
#5 /home/vagrant in /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/CreatesUserProviders.php on line 40 PHP Fatal error: Uncaught InvalidArgumentException: Authentication user provider [external-user] is not defined. in /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/CreatesUserProviders.php:40 Stack trace:
#0 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(123): IlluminateAuthAuthManager->createUserProvider('users')
#1 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(96): IlluminateAuthAuthManager->createSessionDriver('web', Array)
#2 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(70): IlluminateAuthAuthManager->resolve('web')
#3 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(294): IlluminateAuthAuthManager->guard()
#4 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): IlluminateAuthAuthManager->__call('check', Array)
#5 /home/vagrant in /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/CreatesUserProviders.php on line 40 Script php artisan optimize handling the post-install-cmd event returned with error code 255 vagrant@my-api:~/Code/my-api$
这是我config/auth.php
:
<?php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'jwt',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'external-user',
'model' => DncExtensionsDncUser::class,
],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
],
];
这是我app/Providers/AuthServiceProvider.php
:
use DncExtensionsExternalUserUserProvider;
use IlluminateFoundationSupportProvidersAuthServiceProvider as ServiceProvider;
use IlluminateSupportFacadesAuth;
class AuthServiceProvider extends ServiceProvider
{
protected $policies = [];
public function boot()
{
$this->registerPolicies();
Auth::provider('external-user', function ($app, array $config) {
return new ExternalUserUserProvider();
});
}
}
这是我custom UserProvider
:
namespace DncExtensions;
use IlluminateContractsAuthAuthenticatable;
use IlluminateContractsAuthUserProvider as IlluminateUserProvider;
class ExternalUserUserProvider implements IlluminateUserProvider
{
public function retrieveById($identifier)
{
// ...
}
public function retrieveByToken($identifier, $token)
{
// T...
}
public function updateRememberToken(Authenticatable $user, $token)
{
// ...
}
public function retrieveByCredentials(array $credentials)
{
//. ..
}
public function validateCredentials(Authenticatable $user, array $credentials)
{
// ...
}
}
和我的custom User
:
命名空间 Dnc\Extensions;
use IlluminateFoundationAuthUser as Authenticatable;
use TymonJWTAuthContractsJWTSubject;
class DncUser extends Authenticatable implements JWTSubject
{
// ...
}
作曲家版本: 1.4.1 2017-03-10 09:29:45
这是我的作曲家.json
相同的错误PHP 致命错误:未捕获 无效参数异常:未定义身份验证用户提供程序 [外部用户]。我只
执行php artisan optimize
知道如何解决此错误吗?
重要信息
我刚刚意识到php artisan optimize
在composer install
后运行良好,但在composer install --no-dev
后失败
尝试在 .env 文件中进行更改
APP_ENV=local
自
APP_ENV=production