1 回答
TA贡献1804条经验 获得超3个赞
我想到了。
我使用查询生成器连接控制器上的三个表(员工、工资单、职位):
public function show(Employees $employee, Payrolls $payroll)
{
$basic_pay = DB::table('payrolls')
->join('employees', 'employees.id', '=', 'payrolls.employees_id')
->join('positions', 'positions.id', '=', 'employees.positions_id')
->select('positions.basic_pay')
->where('payrolls.employees_id', '=', $payroll->employees_id)
->get();
$position_name = DB::table('payrolls')
->join('employees', 'employees.id', '=', 'payrolls.employees_id')
->join('positions', 'positions.id', '=', 'employees.positions_id')
->select('positions.name')
->where('payrolls.employees_id', '=', $payroll->employees_id)
->get();
return view('payrolls.show')
->with('payrolls', $payroll)
->with('basic_pay', $basic_pay)
->with('position_name', $position_name)
->with('employees', $employee);
}
以及我的看法:
<label><h4>Position: </h4></label>
<span style="font-size: 25px">
{{ $position_name->pluck('name')->first() }}
</span><br>
<label><h4>Basic Pay: </h4></label>
<span style="font-size: 25px">
{{ $basic_pay->pluck('basic_pay')->first() }}
</span><br>
我使用 pluck 来选取我想要显示的所需列字段。
- 1 回答
- 0 关注
- 109 浏览
添加回答
举报