1
votes

Sorry if my question looks so basic...

Am trying to use the following package in a fresh Laravel7 installation.

https://github.com/phpclassic/php-shopify

As like they mentioned i used 'composer require phpclassic/php-shopify' command to install this package. It is done successfully and i see it under 'Vendor/phpclassic/php-shopify/' folder. Now i want to use it in my controller...

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use PHPShopify\ShopifySDK;

class ShopifyConnectionController extends Controller
{
    function index(Request $request){

        $config = array(
            'ShopUrl' => config('app.shopify_app_url'),
            'ApiKey' => config('app.shopify_app_api_key'),
            'SharedSecret' => config('app.shopify_app_api_secret'),
        );

        PHPShopify\ShopifySDK::config($config);
        dd($request->all());
    }
}
?>

Am getting following error...

Error
Class 'App\Http\Controllers\PHPShopify\ShopifySDK' not found 

Now i see that the package is not auto loaded. I tried using "composer dump-autoload" command and tried adding the folder path in autoload section of composer.json file, etc... am keep getting the same error... I also noticed the "composer dump-autoload" command showing...

Discovered Package: facade/ignition 
Discovered Package: fideloper/proxy
etc...

but not the package i installed. Those discovered packages also in the same vendor folder. Then why is my package is not being discovered by Composer autoload when i run that command ? Someone kindly help.

1

1 Answers

5
votes

You are simply missing a backslash. This tells the autoloader that the file you are looking for is not in the namespace your controller resides in.

\PHPShopify\ShopifySDK::config($config);

And since you've already imported ShopifySDK there's no need for a FQCN. Just use the class:

ShopifySDK::config($config);