$stocks = StocksUnderMedication::where('user_id', Auth::user()->id)->get();
上面的代码获取“ StocksUnderMedication”表中的所有行。
$originals = Stock::where('user_id', Auth::user()->id)->get();
上面的代码获取“股票”表中的所有行。
我正在尝试获取Stock表中“ tag_no”等于StockUnderMedication表中“ tag”的所有行。
即Stock表具有tag_no字段,而StockUnderMedication具有tag字段。
我该如何实现?
答案 0 :(得分:1)
@foreach( $stocks as $stock )
<tr>
<td>{{ $stock->tag_no }}</td>
@foreach( $originals as$original )
@if( $original->tag_no == $stock->tag_no )
<td>{{ $original->stock_type }}</td>
@endif
@endforeach
<td>{{ $stock->description }}</td>
</tr>
@endforeach
此代码将解决问题。 在视图页面中使用以上逻辑。 只需使用嵌套的foreach即可,但最好使用idk,但效果很好。