A
A
Alexander Shapoval2016-05-17 20:08:25
Laravel
Alexander Shapoval, 2016-05-17 20:08:25

Laravel. Selecting the necessary data from the database, and placing it in a one-dimensional array. How can be done?

You can make a cycle, but I don’t want to (laziness, you know, you quickly get used to the good).
There is a code
return DB::table('category')->lists('name', 'id');
Works as it should. Returns a one-dimensional array

[
'0' => 'value1',
'1' => 'value2'
...
]

Only I need to add a where selection condition , and that would return exactly the same array.
I am writing a similar design.
DB::table('category')
  ->where('primary', 'yes')
  ->get();

It returns an array of categories as a list of stdClass, which is not acceptable.
In general, how to avoid writing a loop and use Laravel's built-in methods? This is not the first time I've hit my head on the ceiling in this place.
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Perin, 2016-05-17
@AlexanderShapoval

return DB::table('category')->where('primary', 'yes')->lists('name', 'id');

D
D', 2016-05-17
@Denormalization

Make a model and use Eloquent - what does not allow?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question