【发布时间】:2020-06-17 08:28:54
【问题描述】:
我有 2 个模型:
- 属性(字段:prop_id、a、b、c)
- OfferDemandmatch(字段:prop_id d、e、f)
两个模型都有 prop_id 列,必须使用它来连接两个模型。
我有一个刀片视图,我在其中为匹配集合执行 foreach,并且我需要在每个集合项中包含来自 Property 和 OfferDemandmatch 模型的字段。
这是发送到 balde view 的 Match 集合的代码
class OfferdemandsmatchsController extends Controller
{
public function index ($id) {
$matchs = OfferDemand::findOrFail($id)->offerdemandsmatchs;
return view('pages.processes.offerdemand.matchs.index', compact('matchs'));
}
}
这是刀片视图中的代码
<div class="row">
@foreach($matchs as $match)
@component('pages.processes.offerdemand.matchs.matchbox')
@endcomponent
@endforeach
</div>
我需要在刀片视图的每个foreach 迭代中使用属性和匹配字段。所以,我的收藏项必须包含字段:prop_id、a、b、c、d、e、f
我怎样才能做到这一点?
问候
【问题讨论】:
-
您需要提供更多信息,例如型号代码和对预期响应的更多解释。为什么不使用模型之间的关系?
-
在最后一段中,他想要一个来自 2 个表的完全联接
标签: laravel laravel-5 eloquent