I have an existing array named $list
I want to add new field or data in that array but I dont know how to. I have this code
$list = DB::table('transaction_tickets')
->leftJoin('airlines','transaction_tickets.airline_id','=','airlines.id')
->select('transaction_tickets.*',....)
->get();
$inputs = array();
foreach ($list as $key => $value) {
$inputs[$key] = $value;
}
Laravel 5 has a method to do this for you: pluck()
$inputs = $list->pluck($property);
For earlier versions of Laravel, you may have to use the lists()
method instead
$inputs = $list->lists($property);
Eloquent get
method returns a collection.
So you can add values to this collection.
Use $list->put('key', 'value') ;