php - Laravel 社交名流未定义类型
问题描述
我试图创建一个 Facebook 登录 API,但在我的
FbController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
use Validator;
use Socialite;
use Exception;
use Auth;
class FbController extends Controller
{
public function redirectToFacebook()
{
return Socialite::driver('facebook')->redirect();
}
public function facebookSignin()
{
try {
$user = Socialite::driver('facebook')->user();
$facebookId = User::where('facebook_id', $user->id)->first();
if($facebookId){
Auth::login($facebookId);
return redirect('/dashboard');
}else{
$createUser = User::create([
'name' => $user->name,
'email' => $user->email,
'facebook_id' => $user->id,
'password' => encrypt('john123')
]);
Auth::login($createUser);
return redirect('/dashboard');
}
} catch (Exception $exception) {
dd($exception->getMessage());
}
}
}
当我使用 Facebook 登录时,它可以工作,但是当它重定向到我的仪表板时,它给了我一个空白页面......
仪表板.blade.php
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Dashboard') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
<x-jet-welcome />
</div>
</div>
</div>
</x-app-layout>
我试图为社交名流导入课程,但我发现它不是课程,Auth 也给了我同样的问题
以下是显示的错误...
未定义类型“社交名流”。{“资源”:“/c:/xampp/htdocs/testing/app/Http/Controllers/FbController.php”,“所有者”:“生成诊断集合名称#4”,“代码”:“1009”,“严重性”:8 ,“消息”:“未定义类型'社交名流'。”,“来源”:“intelephense”,“startLineNumber”:23,“startColumn”:21,“endLineNumber”:23,“endColumn”:30}
未定义的类型验证。{“资源”:“/c:/xampp/htdocs/testing/app/Http/Controllers/FbController.php”,“所有者”:“生成诊断集合名称#4”,“代码”:“1009”,“严重性”:8 ,“消息”:“未定义类型'Auth'。”,“来源”:“intelephense”,“startLineNumber”:27,“startColumn”:17,“endLineNumber”:27,“endColumn”:21}
@Cbroe,我相信你现在更好地理解它了......
解决方案
我尝试注释掉我的use AUth;
然后use Socialite;
我添加了
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;
它工作得很好......
推荐阅读
- php - 如何添加类
- wordpress 中的 dynamic_sidebar
- java - 如何根据对象的值获取 10 个对象?
- python - 如何编辑参数格式
- asp.net-core - ASP.NET Core 中的 UseStaticFiles() 和 UseFileServer() 有什么区别?
- python - 有一个具有多个值的 ForeignKey?适当的解决方案?
- node.js - 如何从 express 流式传输大型 xml 响应
- javascript - 基于 Cookie 的 4 天计时器,然后重定向 Javascript
- vba - VBA 从范围复制/粘贴失败
- python - Python:日志记录处理程序仅记录低于错误的日志级别日志
- xamarin.forms - 为什么我的 ContentPresenter 占用的空间比它所呈现的内容更多