0
Is there any way to retrieve the results of a query in the database and transfer it to a Array
with one of the table fields being index of Array
?
You could achieve this result in two steps. After the query makes a loop
and turns into the Array
with desired index.
You can check this result in one step?
This is the code that returns me to query:
$lang = DB::table('language')->select('id', 'name')->get();
I wanted to $lang
is an array of the type $lang[id=>name]
.
It’s just two camps?
– gmsantos
for this query yes, but there are others with more than two. The logic should be the same no?
– zwitterion
If you will iterate yes, but for cases of two fields Laravel has the
lists
– gmsantos
exact. lists works well for 2 fields. thanks
– zwitterion
Possible duplicate of Call to Undefined method Illuminate Database Query Builder::lists()
– novic
Examples: link1, Link2, link3 and Link4
– novic