首页 > 解决方案 > 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,我相信你现在更好地理解它了......

标签: phpapilaravel-8

解决方案


我尝试注释掉我的use AUth;然后use Socialite;我添加了

use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;

它工作得很好......


推荐阅读