Ian B
0
Q:

laravel collection methods

// The array we're going to return
    $data = [];    
// Query the users table
$query = users::where('id', 1)->get();

// Let's Map the results from [$query]
$map = $query->map(
    function($items){
          $data['user_firstName'] = $items->firstName;
          $data['user_lastName'] = $items->lastName;
          return $data;
        }
    );

return $map;
0
$collection = collect([1,2,3,4]);

$collection->each(function($item){
    return $item*$item;
});

// [1,4,9,16]
0

New to Communities?

Join the community