【发布时间】:2016-11-06 20:13:03
【问题描述】:
class Company extends Model
{
public function employees() {
return $this->hasMany('Employee');
}
}
class User extends Model
{
public function employee()
{
return $this->hasMany('Employee');
}
}
class Employee extends Model
{
protected $table = "user_role_company";
public function user(){
return $this->belongsTo('User');
}
public function company(){
return $this->belongsTo('Company');
}
}
我在运行时得到“Column not found: 1054 Unknown column 'user_id' in 'where clause' (SQL: select * from companies where user_id = 55)”:
Company::with('employees')->where('user_id',$user->id)->get();
我做错了什么?
谢谢
【问题讨论】:
-
您的架构在哪里?您是否试图为特定用户获取属于公司的员工?