2

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();

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

Comments

2

You can "use" it on the top of your php source file.

use Drewm\MailChimp;

$MailChimp = new MailChimp();

1 Comment

This works and is a great PHP solution. However, for Laravel projects, I prefer the solution from egig.
0

I would strongly suggest to not rely on the no-longer-documented Laravel feature and just use the PHP native way if you must have this:

if (! class_exists('Setting')) { // in case the same php process is reused
     class_alias(\App\Facades\Setting::class, 'Setting');
}

This is what Laravel was using under the hood either way - and your IDE will immediately recognize it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.