简体   繁体   English

Laravel 社会名流 未定义类型

[英]Laravel Socialite Undefined Type

I was trying to create a Facebook Login API, but I got an undefined type in my我试图创建一个 Facebook 登录 API,但我在我的

FbController.php 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());
        }
    }
}

when I used the Facebook Login, it worked but when it redirected to my dashboard it gave me a blank page...当我使用 Facebook 登录时,它可以工作,但是当它重定向到我的仪表板时,它给了我一个空白页...

Dashboard.blade.php仪表板.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>

I tried to import the class for socialite but I discovered that it was not a class, the Auth also gave me the same problem我尝试为社交名流导入 class 但我发现它不是 class,Auth 也给了我同样的问题

Below are the errors displayed...以下是显示的错误...

Undefined type 'Socialite'.未定义类型“社交名流”。 { "resource": "/c:/xampp/htdocs/testing/app/Http/Controllers/FbController.php", "owner": " generated_diagnostic_collection_name #4", "code": "1009", "severity": 8, "message": "Undefined type 'Socialite'.", "source": "intelephense", "startLineNumber": 23, "startColumn": 21, "endLineNumber": 23, "endColumn": 30 } {“资源”:“/c:/xampp/htdocs/testing/app/Http/Controllers/FbController.php”,“所有者”:“生成诊断集合名称#4”,“代码”:“1009”,“严重性”:8 ,“消息”:“未定义类型'社交名流'。”,“来源”:“intelephense”,“startLineNumber”:23,“startColumn”:21,“endLineNumber”:23,“endColumn”:30}

Undefined Type Auth.未定义的类型验证。 { "resource": "/c:/xampp/htdocs/testing/app/Http/Controllers/FbController.php", "owner": " generated_diagnostic_collection_name #4", "code": "1009", "severity": 8, "message": "Undefined type 'Auth'.", "source": "intelephense", "startLineNumber": 27, "startColumn": 17, "endLineNumber": 27, "endColumn": 21 } {“资源”:“/c:/xampp/htdocs/testing/app/Http/Controllers/FbController.php”,“所有者”:“生成诊断集合名称#4”,“代码”:“1009”,“严重性”:8 ,“消息”:“未定义类型'Auth'。”,“来源”:“intelephense”,“startLineNumber”:27,“startColumn”:17,“endLineNumber”:27,“endColumn”:21}

@Cbroe, I believe you understand it better now... @Cbroe,我相信你现在更好地理解它了......

I tried commenting out my use AUth;我尝试注释掉我的use AUth; and use Socialite;use Socialite; then I added然后我添加了

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

and it worked perfectly...它工作得很好......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM