【问题标题】:Laravel Socialite Undefined TypeLaravel 社交名流未定义类型
【发布时间】:2021-07-28 16:44:19
【问题描述】:

我试图创建一个 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 登录时,它可以工作,但是当它重定向到我的仪表板时,它给了我一个空白页面...

Dashboard.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", "owner": "generated_diagnostic_collection_name#4", “代码”:“1009”, “严重性”:8, "message": "未定义类型'社交名流'。", “来源”:“intelephene”, “开始线号”:23, “开始列”:21, "endLineNumber": 23, “结束列”:30 }

未定义的类型验证。 { "资源": "/c:/xampp/htdocs/testing/app/Http/Controllers/FbController.php", "owner": "generated_diagnostic_collection_name#4", “代码”:“1009”, “严重性”:8, "message": "未定义类型'Auth'。", “来源”:“intelephene”, “开始线号”:27, “开始列”:17, "endLineNumber": 27, “结束列”:21 }

@Cbroe,我相信你现在明白了……

【问题讨论】:

  • “但我的 FbController.php 中有一个未定义的类型” - 以及 where 确切地说,指的是 what特别是?请逐字引用错误消息,而不是向我们提供您自己的缩短版本,因为缺少必要的细节。
  • 已编辑帖子,您可以再次查看...@CBroe

标签: php api laravel-8


【解决方案1】:

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

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

而且效果很好……

【讨论】:

    猜你喜欢
    • 2018-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-20
    • 2021-02-10
    • 2016-09-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多