[英]Cannot access collection by properties Laravel 5.8
So I have three different arrays with the same length in the request and below is how I combine them into one collection: 因此,我在请求中具有三个相同长度的不同数组,下面是将它们组合为一个集合的方法:
$inputs = collect();
$keys = collect(['id', 'username', 'email']);
foreach ($request['ids'] as $index => $id) {
$username = $request['usernames'][$index];
$email = $request['emails'][$index];
$inputs->push($keys->combine([$id, $username, $email]));
}
The result looks correct to me: 结果对我来说看起来是正确的:
However, I cannot access the collection when I iterate over it: 但是,在迭代集合时,我无法访问它:
foreach ($inputs as $input) {
dd($input->id); // Property [id] does not exist on this collection instance.
}
This is the result of dd($input): 这是dd($ input)的结果:
Any pointers on this problem? 关于这个问题有什么建议吗? (Another short way to combine the arrays into one collection will also be appreciated!)
(将数组组合成一个集合的另一种简短方法也将受到赞赏!)
Thank you. 谢谢。
这是一个集合,您应该像这样获得它: dd($input['id'])
。
You can combine arrays bt array_merge 您可以组合数组bt array_merge
array_merge($a1,$a2)
or collect 或收集
$c=collect([$arr1,$arr2])
then pluck if you want 然后如果你想摘
$c->pluck('username')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.