phplaravellaravel-8laravel-socialite

Getting Error "Undefined type 'Laravel\Socialite\Facades\Socialite'.intelephense(1009)"


I'm getting this weird error. Although i have performed the required steps of installing the "Socialite" package , for instance i have edit the "providers" and "aliases" in "config/app.php". Thing is I'm using this in existing project, but when i created in fresh copy it was working fine.

Undefined type 'Laravel\Socialite\Facades\Socialite'.intelephense(1009)

Here is my controller code (Where i'm getting this error)

   `// Google Registration 

   public function googleRedirect()
   {
   return Socialite::driver('google')->redirect();
   }

   public function loginWithGoogle()
   {
        try
       {
         $user = Socialite::driver('google')->user();
         $existingUser = User::where('google_id',$user->id)->first();

         if($existingUser)
         {
                 Auth::login($existingUser);
                 return redirect('/home');
         }
  
         else{
                $createUser = User::create([
                        $uuid = Str::uuid()->toString(),
                        'name'      =>  $user->name,
                        'email'     =>  $user->email,
                        'google_id' =>  $user->id,
                ]);
       
               Auth::login($createUser);
               return redirect('/timeline');
           }
       }
   catch(\Throwable $th){
   throw $th;
   }
   }

`

PS* I have already imported the required package on the top

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

I have followed all the required steps to install the socialite package, only problem that i'm facing is getting following error in controller:

Undefined type 'Laravel\Socialite\Facades\Socialite'.intelephense(1009)

PS* I'm using Laravel 9.


Solution

  • i review your code use Socialite::driver('google')->stateless()->user(); this instead of Socialite::driver('google')->user();