[英]Laravel 5.3 Multiple Pluck in View undefined variable
i've been using Pluck to return data from other models to views fine. 我一直在使用Pluck将其他模型的数据返回到视图中。 This model however, needs to return 4 bits of data for dropdown lists from 4 different models.
但是,该模型需要返回来自4个不同模型的下拉列表的4位数据。 Whenever I add more than 2 "Plucks" into the controller i get an undefined variable for one of them.
每当我向控制器添加2个以上的“Pluck”时,我会得到一个未定义的变量。 2 works fine though.
2但工作正常。 Here's my code in my controller:
这是我的控制器中的代码:
public function create()
{
return view('products_alloweds.create',
['products' => Products::pluck('product_name', 'id')],
['companies' => Companies::pluck('name', 'id')],
['deliveryaddress' => DeliveryAddresses::pluck('name', 'id')],
['customers' => Customers::pluck('name', 'id')]
);
}
Here's a sample my fields file that returns the data to the view: 这是我的字段文件示例,它将数据返回到视图:
<!-- Da Id Field -->
<div class="form-group col-sm-6">
{!! Form::label('da_id', 'Da Id:') !!}
{!! Form::number('da_id', $deliveryaddress, null, ['class' => 'form-control']) !!}
Like i said it works fine with just 2 but adding more than that results in an undefined variable error for either one of them. 就像我说它只用2就可以正常工作但是添加更多会导致其中任何一个的未定义变量错误。
Thanks 谢谢
From the source code , second parameter of view()
function should be an array as defined below: 从源代码中 ,
view()
函数的第二个参数应该是一个如下定义的数组:
return view('products_alloweds.create',
[
'products' => Products::pluck('product_name', 'id'),
'companies' => Companies::pluck('name', 'id'),
'deliveryaddress' => DeliveryAddresses::pluck('name', 'id'),
'customers' => Customers::pluck('name', 'id')
]
);
whereas you are providing five parameters to the view()
function. 而您为
view()
函数提供了五个参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.