LionHeartBlue's avatar

Get a list of Columns from a table in order

Hi,

So, I am using the following code to get a list of column fields:

$jobFields = Schema::getColumnListing('jobs');

But this returns the columns in alphabetical order (by Name).

How can I preserve the order they appear in the table? So for example, "ID" comes first instead of appearing half way down the list.

0 likes
3 replies
SilenceBringer's avatar
Level 55

@lionheartblue not elegant solution and specific to MySql, but should works

$jobFields = collect(\DB::select('describe jobs'))->pluck('Field')->toArray();
3 likes

Please or to participate in this conversation.