0
@foreach ($despatchitems as $despatchitem)
<tr>
  <td>{{$despatchitem->tag_id}}</td>
  <td>{{$despatchitem->qty}}</td>
  <td>{{$despatchitem->description}}</td>
</tr>
@endforeach 

我需要标签名称而不是tag_id,我怎样才能连接到标签表并获取标签名称

DespatchItem模型和标签模型之间没有直接关系

4

1 回答 1

0

您可以在 DespatchItem 模型中使用belongsTo关系。

public function tags()
{
   return $this->belongsTo('App\Tag','tag_id');
}

并在您的视图中使用,如下所示。

<td>{{$despatchitem->tags->tag_name}}</td>
于 2018-08-01T06:45:05.350 回答