简体   繁体   中英

Laravel Eloquent Order By Alphanumeric value

I am using laravel 6.x, i have rows like this

Plot 4
Plot 5
Plot 2
Plot 4B
Plot 3
Shop 2
Shop 1

I want result like this

Plot 2
Plot 3
Plot 4
Plot 4B
Plot 5
Shop 1
Shop 2

Thanks

If you're using Laravel you should look at their documentation for collections and their sort method.

Start with creating collections: https://laravel.com/docs/6.x/collections#creating-collections

And then look at sorting: https://laravel.com/docs/6.x/collections#method-sort

That should get you there. If you post details of your attempts so far we can help you get it working.

If you're using an eloquent model to get your data from a database then it will come as a collection already then you simply need to sort by the relevant key eg.

Model::all()->sortBy('column');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM