简体   繁体   中英

Laravel PSR-4 not loading classes automatically

I am using a custom folder in app directory which contains Billing, Exceptions, Repositories etc. Here is my directory structure...

app
  -iw
     -Billing
         -BillingInterface.php
         -StripeBilling.php
     -Exceptions
     -Repositories
     -macros.php

composer.json

"psr-4": {
        "iw\\" : "app/iw"
    },

ran command composer dump-autoload -o

Classes

// app/iw/BillingInterface.php (location)

<?php namespace iw\Billing;

interface BillingInterface {}

And

// app/iw/StripeBilling.php (location)

<?php namespace iw\Billing;

class StripeBilling {

    public function bill()
    {
        dd('billing');
    }

}

I am getting class not found error, even i noticed that vendor/composer/autoload_ps4.php is not updating with this new folder. Please help. thanks

Add "app/iw" in "classmap".

"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/models",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php",
        "app/iw"
    ],
    "psr-4" : {
        "iw\\" : "app/iw"
    }
}

and run

 composer dump-autoload -o

I tried this json file and it worked...

"autoload": {
        "psr-4": {"iw\\" : "app/iw" },
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php"
        ]
    }

But please suggest why it worked after adding "psr-4": {"iw\\\\" : "app/iw" } in autoload section.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM