Laravel Passport setup class not found
I am trying to configure a Laravel application to use Passport and am stuck on loading a class in my AppServiceProvider.php. Here's what I did ...
<?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);
}
}
}
This results in the following error:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'S1\Providers\Passport' not found
I had this job but had to rebuild and now I can't get past this error. Something is going on with my namespaces, but I can't figure out what.
source to share
Looks like you forgot to import passport, try adding this
use App\Passport\Passport;
for your AppServiceProvider
<?php // AppServiceProvider.php
namespace S1\Providers;
use App\Passport\Passport;
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);
}
}
}
source to share
namespace App \ Providers;
use Laravel \ Passport \ Passport;
use Illuminate \ Support \ Facades \ Gate; use Laravel \ Passport \ PassportServiceProvider; use Illuminate \ Foundation \ Support \ Providers \ AuthServiceProvider as ServiceProvider;
the AuthServiceProvider class extends the ServiceProvider {/ ** * 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();
Passport::routes();
//
}
}
source to share
Install the correct version Passport
for your specific version Laravel
. Let's say you have Laravel 5.5, install Passport 4.0:
composer require laravel/passport=~4.0
To check your Laravel version:
php artisan --version
or see "laravel/framework": "5.5.*",
under the require object in composer.json
.
source to share