Laravel Jun 28 2019

Pluck multiple values from a Laravel Collection

If you've ever tried to use pluck() to retrieve multiple attributes from a Laravel Collection you've probably been super frustrated to know it's not possible. Here's how to accomplish the same thing.

Instead of doing the following (which does not work):

Post::all()->pluck('name', 'age');

Try the following instead:

Post::all()->map->only('name', 'age');

Source: @sebdedeyne

Last updated on April 2021