[英]Laravel Class Socialite not found
What I did:我做了什么:
"laravel/socialite": "~2.0"
to composer.json
"laravel/socialite": "~2.0"
到composer.json
composer update
composer update
'Laravel\\Socialite\\SocialiteServiceProvider'
to app.php
app.php
添加了提供者'Laravel\\Socialite\\SocialiteServiceProvider'
'Socialite' => 'Laravel\\Socialite\\Facades\\Socialite'
to 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();
}
}
But i still got this error: PHP Fatal error: Class '\\Socialite'
但我仍然收到此错误:
PHP Fatal error: Class '\\Socialite'
Edit编辑
composer dump-autoload
fixed probably the error, but it's still not working correctly. composer dump-autoload
可能修复了错误,但它仍然无法正常工作。
在您的控制器文件中添加
use Laravel\Socialite\Facades\Socialite;
Just below use Illuminate\\Http\\Request;
就在下面
use Illuminate\\Http\\Request;
in your controller add use Socialize;
在您的控制器中添加
use Socialize;
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这对我来说也很困惑
I had the same issue.我遇到过同样的问题。 Clearing the config cache helped me in this situation:
在这种情况下,清除配置缓存对我有帮助:
php artisan config:clear
First of all use ::class,
on your config/app.php首先在你的 config/app.php 上使用
::class,
'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
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
'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
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 ie我遇到了完全相同的问题,经过通常的半小时肆虐后,我意识到我的注册行末尾有一个尾随空格,即
'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!复制和粘贴的困境再次抬起了他们丑陋的头!
在 Laravel 6 或更高版本中,尝试运行此命令
composer require laravel/socialite
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.