Laravel将foreach值嵌入到foreach中 [英] Laravel getting nested foreach values out of foreach
问题描述
@foreach($ getDocs as $ key => $ docs)
@foreach($ docs-> $ b @foreach($ users->详情为$ key2 => $ value2)
//在这里访问不同的东西
@endforeach
@endforeach
@endforeach
我有 上述方法的问题在于 如何解决这个问题。你可以尝试 form
以上的 foreachs 之外,我需要
$ user
的标识,例如 $ user- > id
,我尝试了隐藏字段在上面 foreachs
,并且访问了那个隐藏字段的值并将该值赋给表单中的隐藏字段。
$ user-> id
对于每个记录都是一样的。
pluck
像这样
<$ p $ @ code> @foreach($ getDocs as $ key => $ docs)
@foreach($ docs-> doc_user as $ key1 => $用户)
@php
$ user_ids = $ users-> pluck(id)
@endphp
@foreach($ users-> details as $ key2 = > $ value2)
//在这里访问不同的东西
@endforeach
@endforeach
@endforeach
然后使用 $ user_ids
数组
@foreach ($getDocs as $key => $docs)
@foreach ($docs->doc_user as $key1 => $users)
@foreach ($users->details as $key2 => $value2)
//Accessing different things here
@endforeach
@endforeach
@endforeach
I have form
outside of the above foreachs
, I need the id of $user
like $user->id
, I tried hidden field in the above foreachs
, And accessed the the value of the that hidden field and gave that value to the hidden field in the form.
That problem with the above method is that the $user->id
was the same for every record.
How can i solve this.
You can try pluck
like this
@foreach ($getDocs as $key => $docs)
@foreach ($docs->doc_user as $key1 => $users)
@php
$user_ids = $users->pluck("id")
@endphp
@foreach ($users->details as $key2 => $value2)
//Accessing different things here
@endforeach
@endforeach
@endforeach
and then use $user_ids
array
这篇关于Laravel将foreach值嵌入到foreach中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!