Search code examples
lumenlaravel-passport

How in in lumen app adding laravel\passport fix error in app/Models/User.php?


Reading article : https://medium.com/@misteryomi/integrating-laravel-passport-in-your-lumen-project-with-example-1c2b8719c30

I try to install in lumen app laravel\passport with use of dusterio/lumen-passport pluging, but I stuck on app/Models/User.php modifications :

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use DB;
use Illuminate\Validation\Rule;
use Laravel\Passport\HasApiTokens;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;

class User extends Model implements AuthenticatableContract, AuthorizableContract
{
    use HasApiTokens, Authenticatable, Authorizable;
    protected static $password_length = 8;

I got error message: "Trait 'App\Models\Authenticatable' not found. I tried to include with use ... different file I found in net, but failed.

In my composer.json :

{
    "name": "laravel/lumen",
    "description": "The Laravel Lumen Framework.",
    "keywords": ["framework", "laravel", "lumen"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": "^7.3|^8.0",
        "cviebrock/eloquent-sluggable": "^8.0",
        "dusterio/lumen-passport": "^0.3.4",
        "laravel/lumen-framework": "^8.0",
        "laravel/passport": "^10.1",
        "webpatser/laravel-uuid": "^3.0"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9.1",
        "mockery/mockery": "^1.3.1",
        "phpunit/phpunit": "^9.3"
    },
    "autoload": {
        "files": [
            "app/library/helper.php"
        ],
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ]
    }
}

How to fix it ?

Thanks!


Solution

  • Well, if the application can't find the passport's classes, you can force reinstall the dependencies using the composer command.

    composer require dusterio/lumen-passport
    

    or you can reinstall all the dependencies using

    composer install