这是我的桌子。
╔════════════╤═╤══════════╤═╤═══════╗
║ Insurances │ │ Devices │ │ Brands║
╠════════════╪═╪══════════╪═╪═══════╣
║ id │ │ id │ │ id ║
╟────────────┼─┼──────────┼─┼───────╢
║ IMEI │ │ type │ │ name ║
╟────────────┼─┼──────────┼─┼───────╢
║ device_id │ │ name │ │ ║
╟────────────┼─┼──────────┼─┼───────╢
║ user_id │ │ brand_id │ │ ║
╚════════════╧═╧══════════╧═╧═══════╝
现在我想在表格中显示结果数据
╔══════╤════════════╤═════════════╤══════════════╤═════════╗
║ IMEI │ brand_name │ device_name │ device_price │ user_id ║
╚══════╧════════════╧═════════════╧══════════════╧═════════╝
想象一下它是否是AJAX,并且在将数据发送到视图之前我必须先加入表。我已经在模型中定义了关系。但是使用该with()
方法,我只能同时调用em的2,但是我不知道如何在视图中调用它们。
无论如何,有没有不简单地DB::class
使用口才呢?
您应该能够在控制器中执行类似的操作,以在您的视图中获得该结果。
$insurance = Insurance::with('device.brand')->find($id);
return json_encode([
'imei' => $insurance->IMEI,
'brand_name' => $insurance->device~>brand->name,
'device_name' => $insurance->device->name,
'device_price' => $insurance->device->price
'user_id' => $insurance->user_id
]);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句