【问题标题】:Undefined class Socialite in Spark Laravel 5.4Spark Laravel 5.4 中的未定义类社交名流
【发布时间】:2018-01-11 10:22:37
【问题描述】:

我是 Laravel 和 Spark 的新手,试图弄清楚我应该如何/在哪里添加我的新控制器并添加社交名流。

在我的提供者中我添加了

Laravel\Socialite\SocialiteServiceProvider::class,

在我添加的别名中

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

这是我的 app/HTTP/Controllers/Auth/LoginController 类的样子

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;
    }
}

当我添加use Socialite; 时,我得到未定义的社交名流

我尝试了composer dump-autoloadphp artisan config:clear,但没有任何效果。我做错了吗?

我正在使用 Laravel 5.4 和 Socialite 3.0

谢谢!

【问题讨论】:

  • 假设您执行了composer require laravel/socialite 步骤是否安全?
  • 而做use Laravel\Socialite\Facades\Socialite 会有所作为吗?
  • 是的,我重新安装了它,尝试改用 use Laravel\Socialite\Facades\Socialite 现在我收到以下错误:在 Laravel\Socialite\Facades\Socialite 中找不到方法“with”;
  • 好的,这就是进步 - 它可以找到课程。新错误是因为它应该是Socialite::driver('github'),而不是Socialite::with('github')
  • 我还得到了Laravel\Socialite\Facades\Socialite;中找不到的方法“驱动程序”,外观中唯一可用的方法是getFacadeAccessor,但我应该可以使用其他功能吧?

标签: php laravel-5.4 laravel-socialite laravel-spark


【解决方案1】:
php artisan clear-compiled 
composer dump-autoload
php artisan optimize

这将清除当前编译的文件,更新它需要的类,然后将它们写回,这样您就不必再这样做了。

【讨论】:

  • 试过了,还是不行:/我尝试使用的任何别名都无法识别。尝试重新启动 Phpstorm IDE,似乎没有任何效果
猜你喜欢
  • 2021-07-28
  • 2017-10-01
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-20
  • 1970-01-01
相关资源
最近更新 更多