database - 无法声明类 App\User,因为该名称已在我的浏览器中使用

标签 database laravel model eloquent

当我运行程序时。我的模型用户有问题。路径 App\Models\User.php

 <?php

 namespace App;

 use Illuminate\Notifications\Notifiable;
 use Illuminate\Contracts\Auth\MustVerifyEmail;
 use Illuminate\Foundation\Auth\User as Authenticatable;
 use App\Presence;
 use App\Models\Project;
 use App\Productivity;
 use App\Sick_leave;
 use App\Annual_leave;
 use App\Models\Team;

 class User extends Authenticatable
 {
   use Notifiable;

/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'name', 'email', 'password', 'level',
];

/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
protected $hidden = [
    'password', 'remember_token',
];

public function presence()
    {
        return $this->hasOne(Presence::class, 'astrowatch', 'user_id', 'presence_id');
    }

public function role()
    {
        return $this->belongsTo(Role::class, 'role_id');
    }

public function permission()
    {
        return $this->hasMany(Permission::class);
    }

public function teams()
    {
        return $this->belongsToMany(Team::class, 'user_teams');
    }
  }

错误是

在我的浏览器中“无法声明类 App\User,因为该名称已在使用中”。 我试过 use Illuminate\Database\Eloquent\User as EloquentUser 但没有任何改变,仍然是错误。

这个错误 error image

最佳答案

改变你的命名空间

<?php

namespace App\Models;

 use Illuminate\Notifications\Notifiable;
 use Illuminate\Contracts\Auth\MustVerifyEmail;
 use Illuminate\Foundation\Auth\User as Authenticatable;
 use App\Presence;
 use App\Models\Project;
 use App\Productivity;
 use App\Sick_leave;
 use App\Annual_leave;
 use App\Models\Team;

 class User extends Model implements Authenticatable
 {
   use Notifiable;

/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'name', 'email', 'password', 'level',
];

/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
protected $hidden = [
    'password', 'remember_token',
];

public function presence()
{
    return $this->hasOne(Presence::class, 'astrowatch', 'user_id','presence_id');
}

public function role()
{
    return $this->belongsTo(Role::class, 'role_id');
}


}

这会解决你的命名空间问题

关于database - 无法声明类 App\User,因为该名称已在我的浏览器中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52828949/

相关文章:

php - 从 laravel 将 DOB 插入 mysql

laravel - 测试用例在通过测试用例上传文件时删除原始文件

node.js - 为什么mongoose要这样设计?

javascript - Extjs 有一个协会

python - 如何创建用于在 mongoDB 数据库中搜索的网页?

c# - 将 SQL Server 数据库添加到 Visual Studio 2013 ASP.Net 网页

ruby-on-rails - 多日期选择器的 Rails 数据设计

php - 开发 Laravel 3 和 Laravel 4

mysql - 数据库设计确保一对一关系

Django-从模型中的所有对象获取第一个属性