[英]Laravel(how to bring two columns from two separate tables in one .blade file) without touching the DB?
从视图中的两个表返回数据的最有效方法是什么?
就像员工一样,检查每个订单的车辆。
Route::get('orderVehicle',"adminController@orderVehicle");
public function orderVehicle(Request $reques){
$orders = new Order;
$vehicles = new Vehicle; $orders->id; $vehicles->id; return view('adminVeiw.orderVehicle',compact('orders','vehicles')); }
@foreach($orders as $or) {{ $or->id }} @endforeach {{ $vehicles->id }}
错误是
“试图获取非对象的属性'id'(视图:/var/www/html/full-Restaurant-App-Using-Laravel/resources/views/adminVeiw/orderVehicle.blade.php)”
有什么建议吗?
如果您不想在控制器中更改代码,请执行此操作
@foreach($orders as $or)
@if(!empty($or->id))
{{ $or->id }}
@endif
@endforeach
@if(!empty($vahicles->id))
{{ $vehicles->id }}
@endif
在这种情况下,您不会出错,但我不知道您想如何为您工作,希望对您有所帮助
public function orderVehicle()
{
$orders = Order::create();
$vehicles = Vehicle::create();
return view('adminVeiw.orderVehicle', compact('orders', 'vehicles'));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.