I was trying to create a Facebook Login API, but I got an undefined type in my
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...
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>
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
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 }
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 }
@Cbroe, I believe you understand it better now...
I tried commenting out my use AUth;
and use Socialite;
then I added
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;
and it worked perfectly...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.