3
votes

I'm trying to implement Socialiate for Laravel 5.5 using this guide https://scotch.io/tutorials/laravel-social-authentication-with-socialite. Data is returned properly from the provider, but I am having trouble defining Use and Namespaces.

With this configuration:

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Socialite;

The result is:

Class 'App\Http\Controllers\Auth\User' not found

Triggered by:

$authUser = User::where('providerId', $user->id)->first();

But, if I add App\User:

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\User;
use Socialite;

The result is:

Class 'App\Http\Controllers\Auth\Auth' not found

Triggered by:

Auth::login($authUser, true);

Any help is much appreciated.

3
what happens if you do $authUser = \User::where('providerId', $user->id)->first();Dhaval Chheda
read this github.com/laravel/socialite it's will help youBilal Ahmed
Then I get "Class 'User' not found"clund

3 Answers

7
votes

You didnt import Auth namespace the right way.

The proper namespace is Illuminate\Support\Facades\Auth;

Add use Illuminate\Support\Facades\Auth; at the top of your class.

1
votes

Try Also, adding use App\User;

namespace App\Http\Controllers\Auth;

use Socialite;
use App\User; 
0
votes

in my case help came when i see that included files were only user and not the socialproviders table in the name space i use two tables Users and Social_providers .. it took 2 days to resolve eaten 4 gb data.

enter code here

namespace App\Http\Controllers\Auth;
use Socialite;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\Models\User;
use App\Models\socialProvider;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
//use Laravel\Socialite\Facades\Socialite;

class RegisterController extends Controller