Lumen/Laravel - Method to extract specific property from objects in an array of objects?

Narktor

I have the following data:

    [{
      "id": 1,
      "name": "test1",
      "created_at": "2020-01-30 15:55:44",
      "updated_at": "2020-01-30 15:55:44"
    }, {
      "id": 2,
      "name": "test12",
      "created_at": "2020-01-30 15:55:44",
      "updated_at": "2020-01-30 15:55:44"
    }, {
      "id": 3,
      "name": "test123",
      "created_at": "2020-01-30 15:55:44",
      "updated_at": "2020-01-30 15:55:44"
    }, {
      "id": 4,
      "name": "test1234",
      "created_at": "2020-01-30 15:55:44",
      "updated_at": "2020-01-30 15:55:44"
    }, {
      "id": 5,
      "name": "test12345",
      "created_at": "2020-01-30 15:55:44",
      "updated_at": "2020-01-30 15:55:44"
    }, {
      "id": 6,
      "name": "test123456",
      "created_at": "2020-01-30 15:55:44",
      "updated_at": "2020-01-30 15:55:44"
    }, {
      "id": 7,
      "name": "test1234567",
      "created_at": "2020-01-30 15:55:44",
      "updated_at": "2020-01-30 15:55:44"
    }, {
      "id": 8,
      "name": "test12345678",
      "created_at": "2020-01-30 15:55:44",
      "updated_at": "2020-01-30 15:55:44"
    }, {
      "id": 9,
      "name": "test123456789",
      "created_at": "2020-01-30 15:55:44",
      "updated_at": "2020-01-30 15:55:44"
    }, {
      "id": 10,
      "name": "test1234567890",
      "created_at": "2020-01-30 15:55:44",
      "updated_at": "2020-01-30 15:55:44"
    }, {
      "id": 11,
      "name": "test12345678901",
      "created_at": "2020-01-30 15:55:44",
      "updated_at": "2020-01-30 15:55:44"
    }, {
      "id": 12,
      "name": "test123456789012",
      "created_at": "2020-01-30 15:55:44",
      "updated_at": "2020-01-30 15:55:44"
    }]

This data was retrieved via eloquent model, like this:

$ad_groups = Ad_user::find($request->decodedToken->user_id)->ad_groups()->get();

I don't know if any "inherited" functionality of eloquent model still resides within $ad_groups, thats why Im posting it here for you so you know what we have to work with ^^

What I basically want to accomplish is to get the ids extraced. I could of course just write a foreach loop. But I'm new to Lumen/Laravel and I'd like to know whether there is also some awesome method like ...>getMeWhatIWant() available in this context or not :D

mdexp

You can use the pluck method on a Laravel collection (official docs here).

You just have to pass the column name that you want to retrieve as first parameter:

$ids = $ad_groups->pluck('id');
dd($ids);

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to extract a property from array of objects and slice it?

分類Dev

Sorting a PHP array of objects such that adjacent objects don't share specific property values

分類Dev

Javascript: extract objects from inside an array of objects, and put them into a new array

分類Dev

javascript return property value from nested array of objects based on condition

分類Dev

Fetch unique values from array of objects based on dynamically passed property

分類Dev

Sort array of objects by property length

分類Dev

Obtain one property of an array of objects

分類Dev

Remove Specific Item From Array With Class Objects Inside

分類Dev

Passing an array of objects to a method in java

分類Dev

JS filtering array in object property of array of objects

分類Dev

Extract child objects into array inside MongoDB aggregation

分類Dev

Filter an array of objects by a property containing a substring in AngularJS

分類Dev

Group array of objects by string property value in JavaScript?

分類Dev

Efficient way to swap property values in array of objects

分類Dev

Convert an array of objects to a hash based on a property of the object

分類Dev

Getting array of objects from CodableAlamofire

分類Dev

Check meter from array of objects

分類Dev

Removing an object from an array of objects

分類Dev

PHP array with only objects of a specific class

分類Dev

Group Array of objects into specific format using lodash

分類Dev

How to convert javascript array to specific list of objects

分類Dev

Get property of an objects subobject from string

分類Dev

Find the value inside the array of objects that include children from the array of objects

分類Dev

How to get unique an array of objects back from a complex an array of objects?

分類Dev

Maintain Array of Objects when using product method

分類Dev

Generating specific fields from JSON objects

分類Dev

Allow 'block objects' from a specific site

分類Dev

How to know quantity of objects that has specific property in common?

分類Dev

Sorting an array based on property value of another array of objects

Related 関連記事

  1. 1

    How to extract a property from array of objects and slice it?

  2. 2

    Sorting a PHP array of objects such that adjacent objects don't share specific property values

  3. 3

    Javascript: extract objects from inside an array of objects, and put them into a new array

  4. 4

    javascript return property value from nested array of objects based on condition

  5. 5

    Fetch unique values from array of objects based on dynamically passed property

  6. 6

    Sort array of objects by property length

  7. 7

    Obtain one property of an array of objects

  8. 8

    Remove Specific Item From Array With Class Objects Inside

  9. 9

    Passing an array of objects to a method in java

  10. 10

    JS filtering array in object property of array of objects

  11. 11

    Extract child objects into array inside MongoDB aggregation

  12. 12

    Filter an array of objects by a property containing a substring in AngularJS

  13. 13

    Group array of objects by string property value in JavaScript?

  14. 14

    Efficient way to swap property values in array of objects

  15. 15

    Convert an array of objects to a hash based on a property of the object

  16. 16

    Getting array of objects from CodableAlamofire

  17. 17

    Check meter from array of objects

  18. 18

    Removing an object from an array of objects

  19. 19

    PHP array with only objects of a specific class

  20. 20

    Group Array of objects into specific format using lodash

  21. 21

    How to convert javascript array to specific list of objects

  22. 22

    Get property of an objects subobject from string

  23. 23

    Find the value inside the array of objects that include children from the array of objects

  24. 24

    How to get unique an array of objects back from a complex an array of objects?

  25. 25

    Maintain Array of Objects when using product method

  26. 26

    Generating specific fields from JSON objects

  27. 27

    Allow 'block objects' from a specific site

  28. 28

    How to know quantity of objects that has specific property in common?

  29. 29

    Sorting an array based on property value of another array of objects

ホットタグ

アーカイブ