Fan
Fan

Reputation: 1180

How to array_values laravel collection?

I have a search result from image model and $photo saved the data which $photo->type == 'photo'.

$photo = $image->filter(function($photo,$key) use($path){
    if($photo->type == 'photo'){
        $photo->url = $path.$photo->image;
             return $photo;
    }
});

Here is the $photo collection and is there any way to array_values() the items data?

Collection {#352 ▼
  #items: array:3 [▼
    2 => ImageBanquet {#349 ▶}
    3 => ImageBanquet {#350 ▶}
    4 => ImageBanquet {#351 ▶}
  ]
}

Upvotes: 13

Views: 10003

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163768

Check values() collection helper.

$values = $collection->values();

Upvotes: 23

Related Questions