Download the PHP package arneetsingh/laravel-customsort without Composer
On this page you can find all versions of the php package arneetsingh/laravel-customsort. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download arneetsingh/laravel-customsort
More information about arneetsingh/laravel-customsort
Files in arneetsingh/laravel-customsort
Package laravel-customsort
Short Description A package to manually sort records of a eloquent model in custom order
License MIT
Homepage https://github.com/arneetsingh/laravel-customsort
Informations about the package laravel-customsort
Manually sort records of a eloquent model in custom order
Problem it solves:
Say there is a need to show certain records of posts, eg. featured posts on top in your listing page. Just a custom order set by user to show specific posts in a specific order on top.
Installation
You can install the package via composer:
Publish and run the migrations with:
You can publish the config file with:
Usage
Model
Use the CanCustomSort
trait in your model you want to have the ability of sorting manually.
Setting the order
Lets say we have 5 posts in our Post model. and we want to set them in order of ids - 2,4,1,5,3
Do note you don't need to pass all of your posts, you can though. Just the ones passed will be returned on top in that order.
Fetching in Custom Order
Will return post in order set first, and then rest of posts.
Set Priority per model basis
If the priority no is higher than other posts, it will be moved to top in results.
Example
Lets say we have 5 posts in our Post model. and we want to set them in order of ids - 2,4,1,5,3
Controller code could look like

Frontend Tips
I used SortabelJS for having the ability to drag and drop to set manual order. And here is snippet to javascript code.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Arneet Singh
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-customsort with dependencies
spatie/laravel-package-tools Version ^1.9.2
illuminate/contracts Version ^9.0