How to use third party package in Laravel?

laravel, laravel-4, php

Solution

If the package provides a ServiceProvider, add it to `app/config/app.php`.

Otherwise composer has already took care of autoloading for you, so you just have to:

$package = new Package;

In the cases where the package is namespaced, you'll have to:

$package = new PackageNamespace\Package;

To be sure, take a look at the `vendor/composer/autoload_*` files, usually `vendor/composer/autoload_classmap.php`, search for the package name or class name and you'll see how it is named. Or just take a look at the main package souce file, usually in:

vendor/vendorName/packageName/[src or lib or whatever]/Package.php

EDIT

I just installed it here and did:

Route::get('test', function()
{
    dd(new WideImage\WideImage);
});

Works like a charm. This package is in the 'namespaced' case I wrote above.

Problem

I'm using Laravel 4 and I want to use a third party package within this framework. I did this to install it: 1) Add package name to composer.json file 2) Run `composer update` command Now I have package available in /vendors folder. My question is, how to use it inside the Laravel now? Looking in the config/app.php file, I can not add it to "providers" array as far as I can see, nor "aliases". When I try to instantiate that package class directly in controller I get the error "Class not found" ( I tried full name to the class: `$pack = new /vendor/package.../class.php` ) Any help on how to include and use the class in the laravel greatly appreciated

Original source