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.

Share:
34,664
Elias Tutungi
Author by

Elias Tutungi

Updated on January 07, 2020

Comments

  • Elias Tutungi
    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/"
        }
    },
    

    I get this error: enter image description here

    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:

    enter image description here

    I use PhpStorm and he recognizes the namespace enter image description here

    I do not know what may be happening, I used composer dump-autoload and nothing.

    • SameOldNick
      SameOldNick over 6 years
      Is config.optimize-autoloader in composer.json set to true? If so, take a look at this: stackoverflow.com/questions/25619063/…
    • Elias Tutungi
      Elias Tutungi over 6 years
      Yes, its is set to true, i removed composer.lock file and used composer update. I'm waiting for it to end :/
    • Elias Tutungi
      Elias Tutungi over 6 years
      Nothing, its not work :/
    • SameOldNick
      SameOldNick over 6 years
      If nothing is working, I'd suggest evaluating why you need your core application code outside of the App namespace and not in a namespace like App\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
      Elias Tutungi over 6 years
      The 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
    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
    Elias Tutungi over 6 years
    Y use php artisan clear-compiled and composer dump-autoload and nothing.. :/
  • Elias Tutungi
    Elias Tutungi over 6 years
    I have used this repeatedly and nothing :/