Home » Php » Laravel Class Socialite not found

Laravel Class Socialite not found

Posted by: admin November 29, 2017 Leave a comment

Questions:

What I did:

  • Added "laravel/socialite": "~2.0" to composer.json
  • Run composer update
  • Added provider 'Laravel\Socialite\SocialiteServiceProvider' to app.php
  • Added alias 'Socialite' => 'Laravel\Socialite\Facades\Socialite' to app.php

After all this steps I created a new Controller Class which looks like that:

<?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class AuthController extends Controller {

    public function login()
    {                  
        return \Socialite::with('facebook')->redirect();
    }

}

But i still got this error: PHP Fatal error: Class '\Socialite'

Edit
composer dump-autoload fixed probably the error, but it’s still not working correctly.

Answers:

Just below use Illuminate\Http\Request; in your controller add use Socialize;

Questions:
Answers:

Check if you have set your alias as “Socialize” as in the Socialite docs says to do this way:

'Socialize' => 'Laravel\Socialite\Facades\Socialite',

It as very confusing to me as well

Questions:
Answers:

I had the same issue. Clearing the config cache helped me in this situation:

php artisan config:clear

Questions:
Answers:

In your Controllers file add

use Laravel\Socialite\Facades\Socialite;

Questions:
Answers:

'Socialite' => 'Laravel\Socialite\Facades\Socialite' is a mistake that I did too.

It must be declared as 'Socialite' => Laravel\Socialite\Facades\Socialite::class

Questions:
Answers:

If anyone still encounters this problem even after trying above solutions, please clear the cache. Most of the time classes and all are cached because of which this error occurs.

php artisan config:clear

Questions:
Answers:

I had the exact same problem and after the usual half hour of raging I realised that there was a trailing space at the end of my registration line i.e.

'Laravel\Socialite\SocialiteServiceProvider ',

Once I’d removed the space funnily enough it worked!

'Laravel\Socialite\SocialiteServiceProvider',

Once again the woes of copy and paste raise their ugly heads!