laravel pluck multiple columns 1

laravel pluck multiple columns

$records = $records->pluck('data', 'id')->toArray();
// [
//	'id' => 'data',
//  ...
//] 

Here is what the above code is Doing:
1. We’re using the `where` method to filter the records.
2. We’re using the `pluck` method to get the data we want.
3. We’re using the `toArray` method to convert the collection to an array.

The `pluck` method is a very powerful method. It allows you to get a specific column from a collection.

You can also use the `pluck` method to get multiple columns.

$records = $records->pluck(‘data’, ‘id’, ‘name’)->toArray();
// [
// ‘id’ => ‘data’,
// ‘name’ => ‘data’,
// …
//]

Similar Posts