Bayasgalan
Bayasgalan

Reputation: 11

include external lib in laravel?

how to include external lib in laravel ? for example twitteroauth.php. no need oauth other packages. because i am converting Symfony code to Laravel. Thanks.

Class 'App\Controllers\Front\TwitterOAuth' not found

.

require_once base_path().'/vendor/twitter/twitteroauth.php';
$twitterOAuth = new TwitterOAuth('app_twitter_consumer_key', 'app_twitter_consumer_secret');

Upvotes: 0

Views: 1012

Answers (1)

Damien Pirsy
Damien Pirsy

Reputation: 25435

Likely you have a namespace problem, Laravel is looking for the class inside the 'App\Controllers\Front' namespace.

If the class is not namespaced, use

$twitterOAuth = new \TwitterOAuth('app_twitter_consumer_key', 'app_twitter_consumer_secret');

(note the backslash before the classname)

otherwise you need to refer to its namespace, something like \Twitter\TwitterOAuth or similar, but only by looking at the class file you can tell.

You could also create an alias for the class. Inside the app\config\app.php file search for the aliases array and add your class:

'Twitter'   => 'TwitterOAuth'   #(or whatever namespace it's in)

By the way, why not using a specific package? Have you looked on http://packagist.org to see if there's a Twitter OAuth package already adapted for Laravel? That would make things a lot easier.

Upvotes: 1

Related Questions