未找到 Laravel 级社交名媛

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28394809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:52:16  来源:igfitidea点击:

Laravel Class Socialite not found

phplaravellaravel-5

提问by Sylnois

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
  • 添加"laravel/socialite": "~2.0"composer.json
  • composer update
  • 将提供程序添加'Laravel\Socialite\SocialiteServiceProvider'app.php
  • 新增别名'Socialite' => 'Laravel\Socialite\Facades\Socialite'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();
    }

}

Buti still got this error: PHP Fatal error: Class '\Socialite'

我仍然收到此错误:PHP Fatal error: Class '\Socialite'

Edit
composer dump-autoloadfixed probably the error, but it's still not working correctly.

编辑
composer dump-autoload可能修复了错误,但它仍然无法正常工作。

回答by Chrisx

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

use Illuminate\Http\Request;在您的控制器下方添加use Socialize;

回答by Shakhawat

In your Controllers file add

在您的控制器文件中添加

use Laravel\Socialite\Facades\Socialite;

回答by Israel Ortu?o

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

检查您是否已将别名设置为“社交”,如 Socialite 文档中所说的那样:

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

It as very confusing to me as well

这对我来说也很困惑

回答by Juergen Kraus

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

我遇到过同样的问题。在这种情况下,清除配置缓存对我有帮助:

php artisan config:clear

php artisan config:clear

回答by Ankita.P

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

回答by KirtJ

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

首先::class,在你的 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

最后检查重定向 URL 是否有效

http://yoursite.com/your_redirect

回答by Néstor

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

'Socialite' => 'Laravel\Socialite\Facades\Socialite'也是我犯的一个错误。

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

它必须声明为 'Socialite' => Laravel\Socialite\Facades\Socialite::class

回答by avishkaME

in laravel 6 or above, try running this command

在 Laravel 6 或更高版本中,尝试运行此命令

composer require laravel/socialite

composer require laravel/socialite

回答by mattl

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 ',

'Laravel\Socialite\SocialiteServiceProvider ',

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

一旦我足够有趣地删除了空间,它就起作用了!

'Laravel\Socialite\SocialiteServiceProvider',

'Laravel\Socialite\SocialiteServiceProvider',

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

复制和粘贴的困境再次抬起了他们丑陋的头!