Answers for "eloquent collection to array"

PHP
4

laravel collection toArray

$collection = collect(['name' => 'Desk', 'price' => 200]);

$collection->toArray();

/*
    [
        ['name' => 'Desk', 'price' => 200],
    ]
*/
Posted by: Guest on July-24-2021
2

add to collection laravel

$item = collect();
$item->push($product);
Posted by: Guest on November-24-2020
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

pluck laravel

$name = DB::table('users')->where('name', 'John')->pluck('name');
Posted by: Guest on January-18-2021

Code answers related to "eloquent collection to array"

Browse Popular Code Answers by Language