Answers for "laravel map function"

PHP
0

collection map laravel

// 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;
Posted by: Guest on September-03-2020
0

laravel map array

collect($deliver_addresses)->map(function ($address) use ($input) {

    $address['id']              = $input['id'];
    $address['a_new_attribute'] = $input['a_new_attribute'];

    return $address;

});
Posted by: Guest on September-27-2021

Browse Popular Code Answers by Language