控制器代码(isn`t工作)Laravel模型,关系如何使用Eloquent进行innjoin查询?
$employees = Employee::with('department')->get();
型号:部门
class Department extends Model
{
...
/**
* Defining Relationships.
*/
public function employee()
{
return $this->hasMany('GloboDeals\Employee');
}
}
型号:员工
class Employee extends Model
{
/**
* Defining Relationships.
*/
....
public function department()
{
return $this->belongsTo('GloboDeals\Department','departments_id','id');
}
外接IDS有table_id
名称。
我搜索和搜索,没有解决方案工作,所以我想我的代码只是blehhh,如果任何人都可以检查出来,并给我一个想法。
您正在寻找一个员工的部门或所有员工的部门? – Vuldo
什么不行?你有错误吗?你会得到意想不到的结果吗?你会得到什么结果?你期望的结果是什么? –
你可以发表表格结构吗? – clod986