laravel eloquent lists - Sorting A List Of Column Values

eloquent, laravel

Solution

You can put whatever you want, and then list it. I mean:

model::orderBy('orderByColumn')->lists('name', 'id');

As long as `lists` is the last method in the chain, other methods works just fine.

Starting from Laravel version 5.3 `lists` is going to be deprecated, use `pluck` instead:

model::orderBy('orderByColumn')->pluck('name', 'id');

Problem

Using laravel and I'm creating a select box on a form. I've been using the helper to create the select box and all is working fine. I retrieve the data for the select box from a database and use the following to retrieve the data: ``` $data = model::lists('name','id') ``` Again all works ok and this returns the expected array My problem though is I can't seem to sort this list - i've tried adding orderBy() but no joy. Other than using a native php function is there a laravel method to sort a list?

Original source