Laravel将foreach值嵌入到foreach中 [英] Laravel getting nested foreach values out of foreach

查看:497
本文介绍了Laravel将foreach值嵌入到foreach中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

($ docs)作为$ key1 => $ users)$ b($ docs-> $ docs)
@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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆