我有这段代码:
@foreach($data as $Branch)
<tr class="item{{$Branch->id}}">
<td> <a class="name">{{$Branch->branchs_name}}</a> </td>
<td> <a class="name">{{$Branch->cashier_id}}</a> </td>
</tr>
@endforeach
您能帮助我如何将此$Branch->cashier_id
发送回控制器以查询收银员的全名?
答案 0 :(得分:2)
而是使用relationship
。在您的belongsTo
模型中建立Branch
关系,例如
public function cashier()
{
return $this->belongsTo('App\Cashier','cashier_id','id');
}
在您看来 -
@foreach($data as $Branch)
<tr class="item{{$Branch->id}}">
<td> <a class="name">{{$Branch->branchs_name}}</a> </td>
<td> <a class="name">{{$Branch->cashier->name}}</a> </td>
</tr>
@endforeach