简体   繁体   中英

How to access a package file form laravel controller

I am using gabrielbull/ups-api in my laravel project

composer.json as follows

"autoload": {
    "psr-4": {
        "App\\": "app/",
        "Ups\\": "vendor/gabrielbull/ups-api/src"
    },
    "classmap": [
        "database/seeds",
        "database/factories"
    ]
},

The controller code as follows:

use Ups\Rate;

$rate = new Ups\Rate($accessKey, $userId, $password);

but I am getting an error Class 'App\Http\Controllers\Ups\Rate' not found

Your controller can't find the Ups\Rate.

You should be able to do:

$rate = new Rate($accessKey, $userId, $password);

If not: You should be able to debug this quick with the following code.

require __DIR__ . '/vendor/autoload.php'
use Ups\Rate;
new Rate()
echo Rate::class; // output

It's a PHP package, so once you install it via composer, it's already autoloaded. You don't have to mess with the composer.json file. After installing run:

composer dumpautoload

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