3

I'm new to Laravel and Spark trying to figure out how/where I should add my new Controllers and add Socialite.

In my providers I added

Laravel\Socialite\SocialiteServiceProvider::class,

In my aliases I added

'Socialite' => Laravel\Socialite\Facades\Socialite::class,

Here's what my app/HTTP/Controllers/Auth/LoginController class looks like

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Socialite;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    /**
     * Redirect the user to the GitHub authentication page.
     *
     * @return Response
     */
    public function redirectToProvider()
    {
        return Socialite::with('github')->redirect();
    }

    /**
     * Obtain the user information from GitHub.
     *
     * @return Response
     */
    public function handleProviderCallback()
    {
        $user = Socialite::driver('github')->user();

        // $user->token;
    }
}

I get undefined class Socialite when I add use Socialite;

I tried composer dump-autoload and php artisan config:clear but nothing is working. Am I doing something wrong?

I'm using Laravel 5.4 and Socialite 3.0

Thanks!

Sam Bellerose
  • 1,782
  • 2
  • 18
  • 43
  • Is it safe to assume you did the `composer require laravel/socialite` step? – ceejayoz Aug 03 '17 at 17:06
  • and does doing `use Laravel\Socialite\Facades\Socialite` instead make a difference? – ceejayoz Aug 03 '17 at 17:07
  • 1
    Yes I re-installed it, tried using use Laravel\Socialite\Facades\Socialite instead and now I get the following error: method "with" not found in Laravel\Socialite\Facades\Socialite; – Sam Bellerose Aug 03 '17 at 18:31
  • OK, so that's progress - it can find the class. The new error is because it should be `Socialite::driver('github')`, not `Socialite::with('github')`. – ceejayoz Aug 03 '17 at 18:44
  • I also get method "driver" not found in `Laravel\Socialite\Facades\Socialite;` the only method available in the facade is getFacadeAccessor but I should be able to use other functions right? – Sam Bellerose Aug 03 '17 at 18:48
  • Since you've got the package installed now, does `use Socialite` work again? – ceejayoz Aug 03 '17 at 18:52
  • No it still doesn't :/ – Sam Bellerose Aug 03 '17 at 19:15

1 Answers1

0
php artisan clear-compiled 
composer dump-autoload
php artisan optimize

This will clear the current compiled files, update the classes it needs and then write them back out so you don't have to do it again.

yoeunes
  • 2,927
  • 2
  • 15
  • 26
  • Tried it and it's still not working :/ any alias I try to use doesn't recognize it. Tried restarting Phpstorm IDE, nothing seems to work – Sam Bellerose Aug 03 '17 at 18:35