Search code examples
phplaravelups

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


Solution

  • 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