如何使用 Laravel Eloquent 先获取特定值然后升序?
How to fetch specific value first then ascending order using Laravel Elequent?
如何使用 Laravel Eloquent 先获取特定值然后升序?
我想先显示 India
然后其他国家。我正在使用
$country_data= country::orderBy('country_id','India')->get();
您可以使用 orderByRaw
mySQL
FIELD
功能
所以试试这个:
$country_data= country::orderByRaw("FIELD(country_id,'India') DESC")->orderBy("country_id","asc")->get();
如何使用 Laravel Eloquent 先获取特定值然后升序?
我想先显示 India
然后其他国家。我正在使用
$country_data= country::orderBy('country_id','India')->get();
您可以使用 orderByRaw
mySQL
FIELD
功能
所以试试这个:
$country_data= country::orderByRaw("FIELD(country_id,'India') DESC")->orderBy("country_id","asc")->get();