2017-05-16 8 views
0

雄弁laravel内のすべてのデータとのOrderBy特定の単語を取得します。 たとえば、私は列名のステータスを持っています。ステータスは「承認済み」、「保留中」、「拒否済み」のストアです。すべてのデータとORDERBY特定の単語を取得する方法を

どのように私はすべてのステータスが降順で「保留」のショーなどのデータを並べ替えることができますか?

+0

ステータス= '拒否' と、ステータス=次いで1 '保留中' を選択し(ケースステータスを2ときステータス= ' New_order as new_order as new_order as table order from new_order asc – JYoThI

答えて

1

これはうまくいくかもしれない:

$data= DB::table('table_name') 
         ->orderby(DB::raw('case when status= "Pending" then 1 when status= "Rejected" then 2 when status= "Approved" then 3 end')) 
         ->get(); 

参照
Question in stackoverflow
Laravel Documentation

関連する問題