PHP

How to retrieve an array of IDs from a collection in Laravel1 min read

To retrieve an array of IDs from a collection in Laravel, you can use the pluck method with the id attribute:

This will retrieve the id attribute for each item in the collection, and return an array containing all of the values.




Alternatively, you can use the map method to transform the items in the collection and return an array of the transformed values:

Both of these approaches will return an array of IDs that can be used for further processing or manipulation.

Leave a Comment