Home > Enterprise >  Trying to override the method of laravel passport package by the help autoload psr-4 but does not ge
Trying to override the method of laravel passport package by the help autoload psr-4 but does not ge

Time:04-19

Composer.json

"autoload": {
        "exclude-from-classmap": [
            "vendor\\laravel\\passport\\src\\Http\\Controllers\\AccessTokenController.php"
        ],
        "psr-4": {
            "App\\": "app/",
            "Laravel\\Passport\\": "app/Override/"  //tried "Passport//" only also
        }
    },

I have file AccessTokenController.php which lie in vendor\laravel\passport\src\Http\Controllers\ and i create Override folder inside App directory on where i copied that file and make changes in code And finally when i do :

composer dump-autoload

i get error as :Class Laravel\Passport\Http\Controllers\AccessTokenController located in ./app/Override/AccessTokenController.php does not comply with psr-4 autoloading standard. Skipping. seems problem with namespace which i couldn't figure out though trying some of the ways .. Anyone can help me ?

CodePudding user response:

I would simply override the route from within the app as mentioned here. No need for the approach you mentioned above.

However, if you want to keep going this route you can try the following.

"psr-4": {
    "App\\": "app/",
}
"exclude-from-classmap": [
    "Laravel\\Passport\\Http\\Controllers\\AccessTokenController"
],
"files": [ 
   "app/Override/AccessTokenController.php"
], 

CodePudding user response:

I solved it by including complete namespace of AccessTokenController.php.so final code would look like this:

"autoload": {
        "exclude-from-classmap": [
            "vendor\\laravel\\passport\\src\\Http\\Controllers\\AccessTokenController.php"
        ],
        "psr-4": {
            "App\\": "app/",
            "Laravel\\Passport\\Http\\Controllers\\":"app/Override/"
        }
    }
  • Related