phpclasslaravelnamespaceslaravel-4

How to add a class alias in Laravel


I added this MailChimp API to Laravel 4 with Composer and I am able to use this API like so:

$MailChimp = new \Drewm\MailChimp();

How can I create an instance of MailChimp() without the path like this:

$MailChimp = new MailChimp();

Solution

  • You can manually add an alias to config/app.php:

    'aliases' => array(
        //other laravel alias
    
        'MailChimp' => 'Drewm\MailChimp'
     );
    

    Now you can use MailChimp anywhere in laravel app.