Laravel And Twitter API as well as thujohn/twitter

- 1 answer

Ad

So I followed his readme and I have done composer dump-autoload a million times, but still I receive an error.

The code:

'providers' => [
    ...
    Thujohn\Twitter\TwitterServiceProvider::class,

],

'aliases' => [

    ...
    'Twitter'   => Thujohn\Twitter\Facades\Twitter::class,
],

In my controller:

class HomeController extends Controller {

    public function index() {
        $tweets = Twitter::getUserTimeline([
            'screen_name' => 'xxxxxxx',
            'count'       => 10,
            'format'      => 'json'
        ]);

        dd($tweets);

        return view('home');
    }

    public function about() {
        return view('about');
    }
}

But I get the error:

FatalErrorException in HomeController.php line 10:
Class 'App\Http\Controllers\Twitter' not found

Um ..... What?

Ad

Answer

Ad

You used non-namespaced name when you refered to Twitter class, so PHP is looking for the class in current namespace. Change that reference to \Twitter or add the following use statement:

use Twitter;
Ad
source: stackoverflow.com
Ad