Support the ongoing development of Laravel.io →
Configuration Eloquent Packages
Last updated 2 years ago.
0

In PHP, you can't import a whole namespace. You can only import specific classes from a namespace.

To test the class has been autoloaded correctly, try replacing Customer_Entity in your code with the fully qualified class name including the namespace, so use:

$customer = \Hco\Magento\Models\Customer_Entity::where('email', '=', $email_address)->first();

If that works, then the class has been autoloaded correctly.

Then I change the use statement to the following: use \Hco\Magento\Models\Customer_Entity;

I'm not sure how forgiving PHP is, but this shouldn't have a preceeding backslash. So try:

use Hco\Magento\Models\Customer_Entity;

Given the class has been autoloaded correctly, that should let you use the class as Customer_Entity locally. You could also alias it if you like, using

use Hco\Magento\Models\Customer_Entity as Customer;

and then be able to use Customer locally.

You shouldn't need to worry about include()ing your class files if you're using Composer autoloading correctly. Also, you would need to use the path to the class, not its namespace.

I highly recommend Dayle Rees' primer on PHP namespaces.

Last updated 2 years ago.
0

You hit on the problem when you said " if you're using Composer autoloading correctly.". I edited the Composer.json file and added change the autoload section to:

    "autoload": {
        "classmap": [
            "src/migrations",
            "src/Hco/Magento/Models",
            "src/Hco/Magento/Providers"
        ],

then I ran "Composer dump-autoload" from command prompt. Then set the use statement to:

use Hco\Magento\Models\Customer_Entity;

Then everything worked just fine. Thanks for pointing me in the right direction. If there is more I should do please let me know but it seems to be working now.

Wayne

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.