1

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;
}
2
  • Which version of laravel are you using? 5.2? Commented May 7, 2016 at 9:54
  • yes I am using laravel 5.2 Commented May 7, 2016 at 10:09

2 Answers 2

1

Eloquent get method returns a collection.

So you can add values to this collection.

Use $list->put('key', 'value') ;

docs

Sign up to request clarification or add additional context in comments.

Comments

0

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.