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.

+3


source to share


5 answers


In yours, AuthServiceProvider.php

change:

use Laravel\Passport\PassportServiceProvider;

      



in

use Laravel\Passport\Passport;

      

+7


source


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);
        }
    }
}

      

+6


source


Please check your composer.json whether or not it included in laravel / passport in "require" like this:

"require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.4.*",
        "laravel/passport": "^3.0",
        "laravel/tinker": "~1.0"
 },

      

if not restart

composer requires laravel / passport

+1


source


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();

    //
}

      

}

0


source


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

.

0


source







All Articles