我正在尝试使用存储在用户表中的我subject_name从表中获取 ,但是每当我尝试这样做时,我都会收到此错误。有什么帮助吗?subjectsubject_id
这种关系是一个用户只能注册一个主题,多个用户可以选择一个主题,因此是一对多的关系
`Illuminate \ Database \ QueryException (42S02)
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'myunimentor_database.subject_user' doesn't exist (SQL: select `subjects`.*, `subject_user`.`user_id` as `pivot_user_id`, `subject_user`.`subject_id` as `pivot_subject_id` from `subjects` inner join `subject_user` on `subjects`.`id` = `subject_user`.`subject_id` where `subject_user`.`user_id` = 1)
Previous exceptions
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'myunimentor_database.subject_user' doesn't exist (42S02)`
用户模型
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\UserType;
use App\Subject;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'first_name', 'last_name', 'type', 'username', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function getAllUsers() {
return User::all();
}
public function userTypes()
{
return $this->belongsTo('App\Users');
}
public function subjects()
{
return $this->belongsToMany('App\Subject');
}
}
眼眸繁星
守着一只汪