[英]Laravel Has Many Through Only brings first record
Well that is my problem. 那是我的问题。
This is the public function in my model 这是我模型中的公共函数
public function traerDesc(){
return $this->hasManyThrough('App\modeloDescripcionVehiculos', 'App\modeloVehiculos', 'idDescripcion', 'id', 'idVehiculo');
}
This is the controller call 这是控制器调用
$data = [
'venta' => modeloAccion::where('accion', 'venta')->with('traerVehiculo', 'traerUsuario', 'traerCliente', 'traerTransaccion', 'traerVenta', 'traerDesc')->get(),
];
return view('modulos.general.informes')->with($data);
This is my table in the blade file 这是我在刀片文件中的表格
<table class="table table-striped table-bordered table-hover" id="myTable">
<thead>
<tr>
<th class="text-center">Vehiculo vendido</th>
<th class="text-center">Precio de compra</th>
<th class="text-center">Precio de venta</th>
<th class="text-center">Ganancia %</th>
<th class="text-center">Usuario</th>
<th class="text-center">Cliente</th>
<th class="text-center">Fecha venta</th>
</tr>
</thead>
<tbody>
@foreach($venta as $ventas)
<tr class="text-center">
@foreach($ventas->traerDesc as $descripcion)
<td>{{$descripcion->marca}}</td>
@endforeach
<td>{{$ventas->traerVehiculo->precioCompra}}</td>
<td>{{$ventas->traerVehiculo->precioVenta}}</td>
<td>asd</td>
<td>{{$ventas->traerUsuario->nombre.' '.$ventas->traerUsuario->apellidoPaterno.' '.$ventas->traerUsuario->apellidoMaterno}}</td>
<td>asd</td>
<td>{{date('d-m-Y', strtotime($ventas->traerVenta->fechaVenta))}}</td>
</tr>
@endforeach
</tbody>
</table>
This is my table accion. 这是我的表格。 As you can see .
如你看到的 。 It has 3 rows where
accion = venta
and all of them has the same info in all the tables. 它有3行,其中
accion = venta
,所有表中都有相同的信息。 But it only brings the first row rejecting the others 但它只会使第一行拒绝其他行
And the view shows only 1 marca
that would be like brand in english. 而这个视图只显示了一个像英文品牌一样的
marca
。
Hope can make myself clear enough. 希望可以让自己清楚。 Thank you
谢谢
Not sure it will help, but you use eager loading method with
wrong way. 不知道它会帮助,但你用预先加载的方法
with
错误的方法。 Right using is: 正确使用是:
Model::with(relations)->where(condition)->get();
Or 要么
Model::where(condition)->get()->load(relations);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.