Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

george1's avatar

How to use an external package under vendor folder in Laravel

Hi,

I am having difficulties using a package which I download using composer on Laravel. The package is under the vendor folder and when I try to include the class in a controller, it says that it doesn't exist. Here's the code fro the controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Dahabtours\Amadeusclient as Amadeusclient;
// use AmadeusDahabtours\SelfServiceApiClient as SelfServiceApiClient;

class AirportController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    
    public function index()
    {
        $api = new Amadeusclient;
        dd($api);
        $amadeus_api = new SelfServiceApiClient("public","secred");
        
        $flight_dates = $amadeus_api->flightDates([
            'origin'        => 'MAD',
            'destination'   => 'MUC'
        ]);

        dd($flight_dates);
    }

Here's the package which I download with composer located right under the vendor folder:

File name: AmadeusClient.php

<?php
/**
 * Amadeus Self-service API PHP SDK
 *
 * @author     Max Tobias Weber <[email protected]>
 */

namespace AmadeusDahabtours;

class SelfServiceApiClient{

  var $api_key;
  var $api_secret;
  var $api_token;
  var $env; // 'DEV' or 'PROD'

The file structure of where the package is located is the following:

vendor
│
└───dahabtours
│   └───amadeusclient
│       │   AmadeusClient.php

Am I missing something? If so, how can I include the package in my controller?

Things I tried already:

  • composer dump-autoload
  • php artisan optimize
  • rebooting my computer
0 likes
2 replies
kokoshneta's avatar

That’s a very odd-looking package.

It’s not strange that it can’t find the class Amadeusclient, because there’s no such class. As the actual source code shows, despite the fact that the file is called AmadeusClient.php, the class name is SelfServiceApiClient. The namespace doesn’t match the folder either.

I have no idea why the author decided that was a good naming scheme (it’s not), but I’m pretty sure it will break Composer’s autoloader.

The easiest way to fix it would be to add the file to autoload > classmap section in your Composer file – that way, PHP will know which file to look for the class in. Then you would use the actual namespace and class in your code, not the names of the folder and file:

// In composer.json
{
	"require": { ... }, // and so on
	"autoload": {
		"classmap": [
			"vendor/dahabtours/amadeusclient/AmadeusClient.php"
		]
	}
}

// In your controller
use AmadeusDahabtours\SelfServiceApiClient;

class AirportController extends Controller {
	public function index() {
		$api = new SelfServiceApiClient;
	}
}
1 like
Sinnbeck's avatar

Using a package that haven't been updated in 4 years might not be the best idea. Personally I would read the code and just implement it myself

Please or to participate in this conversation.