在视图中,我试图@包含一个组件,如:
@foreach($products as $product)
<div class="col m4">
{{$product -> model}}
@include('components.thumb-product', ['model' => $product -> model])
</div>
@endforeach
组件内容。拇指产品:
@extends('layouts.cards.thumb-product-a')
@section('model')
{{$model}}
{{$product -> model}}
@endsection
我在$products中有5个不同的元素,@include(“components.thumb product”)每次迭代都会输出第一个元素。
但是在@foreach中,$product->model(在@include之前)输出了我所期望的:
DBTPI0PGC2、OWQE、TDH、8WFXWRGL、C4M
@include('components.thumb product'),$model&$product->model输出:
DBTPI0PC2、DBTPI0PC2、DBTPI0PC2、DBTPI0PC2、DBTPI0PC2
DBTPI0PC2、DBTPI0PC2、DBTPI0PC2、DBTPI0PC2、DBTPI0PC2
我不知道为什么会这样,我应该使用@include以外的其他东西吗?
请给我指路。