Search code examples
phplaraveleloquentlaravelcollective

Fill LaravelCollective select with data from DB


I'm using LaravelCollective because of the benefits that Form Model Binding offers.

My problem is that I need to fill a select with Categories from the Database so I'm making something like this:

{!! Form::select('size', Category::pluck('name'), null, ['placeholder' => 'Pick a category...']) !!}

The problem with this is that the first option generated has value="0".

I'm looking for a Eloquent way to generate an array ['key' => 'value'] where key is the Id and value is the name. I know I could make a method, get all the categories and generate the Array myself but this isnt what I'm looking for.


Solution

  • Try Category::pluck('name', 'id')