Laravel Class Socialite not found

2019-02-22 21:11发布

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.

8条回答
虎瘦雄心在
2楼-- · 2019-02-22 21:50

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

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

查看更多
▲ chillily
3楼-- · 2019-02-22 21:56

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

查看更多
混吃等死
4楼-- · 2019-02-22 21:57

First of all use ::class, on your config/app.php

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

Second, call the class in your controller

use Socialite;

Third, try clear the config

php artisan config:clear

And lastly check the redirect URL if its working

http://yoursite.com/your_redirect
查看更多
爱情/是我丢掉的垃圾
5楼-- · 2019-02-22 21:58

In your Controllers file add

use Laravel\Socialite\Facades\Socialite;
查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-02-22 22:08

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

查看更多
Emotional °昔
7楼-- · 2019-02-22 22:16

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

php artisan config:clear

查看更多
登录 后发表回答