Composer Autoload Laravel 5.5
34,664
Your code is correct when I tried on my PhpStorm. But you can run the following three commands:
$ php artisan clear-compiled
$ composer dump-autoload
$ php artisan optimize
And this will clear the current compiled files, update the classes it needs and then write them back out so you don't have to do it again.
Author by
Elias Tutungi
Updated on January 07, 2020Comments
-
Elias Tutungi over 4 years
I started a laravel project in version 5.5, I have been working with version 5.1.
In this version I use the folder 'nob' and I use it to develop some classes to turn them into components.
I used the following composer.json in the version 5.1:
"autoload": { "classmap": [ "database" ], "psr-4": { "App\\": "app/", "Nob\\": "nob/" } },
And this is the version 5.5:
"autoload": { "classmap": [ "database/seeds", "database/factories" ], "psr-4": { "App\\": "app/", "Nob\\": "nob/" } },
This is the class, her namespace is correct
<?php namespace Nob\Payeezy\Types; use Nob\Payeezy\Payeezy; class Authorization extends Payeezy {
And this is the tree:
I use PhpStorm and he recognizes the namespace
I do not know what may be happening, I used composer dump-autoload and nothing.
-
SameOldNick over 6 yearsIs
config.optimize-autoloader
in composer.json set to true? If so, take a look at this: stackoverflow.com/questions/25619063/… -
Elias Tutungi over 6 yearsYes, its is set to true, i removed composer.lock file and used composer update. I'm waiting for it to end :/
-
Elias Tutungi over 6 yearsNothing, its not work :/
-
SameOldNick over 6 yearsIf nothing is working, I'd suggest evaluating why you need your core application code outside of the
App
namespace and not in a namespace likeApp\Classes\Nob
. Maybe it should be it's own package? If so, you can have Composer load private packages and see Laravel's documentation on developing packages. -
Elias Tutungi over 6 yearsThe reason is that I worked so well in 5.1 and it worked perfectly, everything of nob does not belong exclusively to that application because I will use it in other projects that I do in parallel, so I do not consider it to be part of the app, but if in 5.5 is the only way that will work, so I'll have to do it like that.
-
-
common sense over 6 years
$ php artisan optimize
is deprecated in Laravel 5.5 (and does nothing) and will be removed in 5.6. laravel-news.com/laravel-5-6-removes-artisan-optimize -
Elias Tutungi over 6 yearsY use php artisan clear-compiled and composer dump-autoload and nothing.. :/
-
Elias Tutungi over 6 yearsI have used this repeatedly and nothing :/