2017-09-08 43 views
0
@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 

form之外上述foreachs的,我需要的$user$user->id的ID,我試過隱藏字段在上面foreachs和訪問的值了該隱藏字段並將該值賦予表單中的隱藏字段。Laravel得到嵌套的foreach值出的foreach

上述方法的問題在於$user->id對於每個記錄都是相同的。

我該如何解決這個問題。

回答

0

你可以嘗試pluck這樣

@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 

然後用$user_ids陣列

+0

好有意義,但是我怎麼可以把它傳遞給隱藏字段的形式。 – Gammer

+0

使用'json_encode($ user_ids)',然後傳遞給隱藏的任何輸入 – C2486