具体错误:
Class '\App\User::class' not found (View: C:\xampp\htdocs\contrex\resources\views\login.blade.php
)
我知道这个问题已多次发布,但我真的无法找到解决方案。
我试图创建一个目录" Models"所以我可以在那里拥有所有模特。在此之前它工作得很好,所以我试图将设置更改回原来的位置 - 但现在它不起作用。
我的User.php
<?php
namespace App;
namespace Illuminate\Foundation\Auth;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Notifications\Notifiable;
class User extends Model implements
AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword;
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'facebook_id',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'remember_token',
];
}
我的UserController.php
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
class UserController extends Controller
{
public function index(){
echo 'index';
}
public function create(){
echo 'create';
}
public function store(Request $request){
echo 'store';
}
public function show(){
}
public function edit($id){
echo 'edit';
}
public function update(Request $request, $id){
echo 'update';
}
public function destroy($id){
echo 'destroy';
}
}
我的SocialAuthController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;
class SocialAuthController extends Controller
{
public function redirect()
{
return Socialite::driver('facebook')->with(['auth_type' => 'rerequest'])->redirect();
}
public function callback()
{
try {
$user = Socialite::driver('facebook')->user();
} catch (Exception $e) {
return redirect('auth/facebook');
}
if($user->email == null)
return Socialite::driver('facebook')->with(['auth_type' => 'rerequest'])->redirect();
$authUser = $this->findOrCreateUser($user);
Auth::login($authUser, true);
return redirect()->route('login');
}
private function findOrCreateUser($facebookUser)
{
$authUser = User::where('facebook_id', $facebookUser->id)->first();
if ($authUser){
return $authUser;
}
return User::create([
'name' => $facebookUser->name,
'email' => $facebookUser->email,
'facebook_id' => $facebookUser->id,
]);
}
}
auth.php上的设置
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => 'App\User::class',
],
composer.json上的设置
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
我尝试了不同的东西 - 也运行php artisan config:clear
等。
有什么想法吗?
答案 0 :(得分:4)
User.php
中有两个名称空间,因此请更改:
namespace Illuminate\Foundation\Auth;
为:
use Illuminate\Foundation\Auth;