Created
November 25, 2020 18:25
-
-
Save IgorDePaula/ecff6b97fb0dbec2f9e15b31d15b6981 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$items = []; | |
foreach ($products as $value) { | |
$items[] = [ | |
'product_id' => $value->id, | |
'name' => $value->name, | |
]; | |
} | |
return collect($items)->all(); | |
================================== | |
return collect($products) | |
->map(function($product){ | |
return ['product_id' => $product->id,'name' => $product->name]; | |
}) | |
->toArray(); | |
================================= | |
return Product::all()->pluck('id','name'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment