我正在尝试配置我的 Laravel 应用程序以使用 Passport,但在我的 AppServiceProvider.php 中加载该类时遇到了困难。这是我所做的…
<?php // AuthServiceProvider.php
namespace S1\Providers;
use Laravel\Passport\PassportServiceProvider;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as
ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
...
public function boot()
{
$this->registerPolicies();
Passport::routes();
Passport::tokensCan([
'client' => 'this is a api client test'
]);
}
}
.
<?php . // auth.php
...
return [
'guards' => [
'web' => [
'driver' => 'passport',
'provider' => 'users',
],
], ...
.
<?php // app.php
'providers' => [
...
Laravel\Passport\PassportServiceProvider::class,
....
.
<?php // AppServiceProvider.php
namespace S1\Providers;
use Illuminate\Support\ServiceProvider;
use S1\Providers\AppServiceProvider;
use Laravel\Passport\PassportServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
// Enable Laravel Migrations Generator for development only
if ($this->app->environment() !== 'production') {
$this->app->register(\Way\Generators\GeneratorsServiceProvider::class);
$this->app->register(\Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider::class);
}
}
}
这样做的结果是出现以下错误:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'S1\Providers\Passport' not found
我确实有这个工作,但不得不重新构建,现在我无法克服这个错误。我的命名空间出了点问题,但我不知道是什么。
原文由 shotdsherrif 发布,翻译遵循 CC BY-SA 4.0 许可协议
在你的
AuthServiceProvider.php
中,更改:到: