0

I want to get all data in a loop. Since I am new to in Laravel i do not know how to do it. Thanks in advance.

My Array looks like this:

array:2 [
0 => Collection { 
#items: array:1 [
  0 => { 
    "id": 3
    "gallery_id": 1
    "is_thumb_image": 1
    "thumbnail": "public\album/kRzunwjAEIXciv1nN2RdsUFB4Ptpu4TjAUSECZCE.jpeg"
  }
]

 }
  1 => Collection {
  #items: array:1 [
  0 => {
    "id": 6
    "gallery_id": 2
    "is_thumb_image": 1
    "thumbnail": "public\album/BKYp72YUZNiZdljDyOjny9HgikR0whlyp0dkLVzV.jpeg"
  }
]}]
4
  • you can convert a collection to an array in laravel $collection->toArray(); Commented Nov 22, 2017 at 5:19
  • how can i convert $TestArr ? Commented Nov 22, 2017 at 5:23
  • u have collection inside array at 0th index foreach($TestArr as $collection) { $arrVal = $collection->toArray(); $arrVal[0]['gallery_id'] } Commented Nov 22, 2017 at 5:57
  • when i use this foreach($TestArr as $collection) { $arrVal = $collection->toArray(); } error : Second array member is not a valid method @Bugfixer Commented Nov 22, 2017 at 6:05

2 Answers 2

1

You should try this: If you use in blade file then below answer helpful you

@foreach($collections as $collection)

   @foreach($colection as $item)
    {{ $item->id; }}
    {{ $item->is_thumb_image; }}
   @endforeach

@endforeach
Sign up to request clarification or add additional context in comments.

3 Comments

I am getting 0,1 collection of array in which 1 array is null like array:2 [ 0 => Collection {#419 ▶} 1 => Collection {#421 ▼items:[] }]. I want to make loop 2 times if in 1st loop i gt data print it..else no data found.Sorry for bad communication.
@ZuberMafat : Please check my updated answer and let me know if any issue
Not getting 100% result. My code is foreach($TestArr as $TestArr) foreach($TestArr as $item) if($item->gallery_id == $val(same as gallary id))<p>image found</p>else<p>image not found</p> endif endforeach endforeach... if $TestArr if i am getting 2 collection of array in whichone array is null... I want it both array in loop if array of element not found then it means i am not getting image thumb.
0

Use foreach loop to display the data ex:

@foreach($collections as $collection)
    @foreach($colection as $item)
        {{ $item->id; }}
        {{ $item->is_thumb_image; }}
    @endforeach
@endforeach

1 Comment

when I dd($TestArr); i got the result which added on question. So how can i use foreach loop as $collection ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.