1. Go to this page and download the library: Download hichxm/laravel-sortable library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hichxm / laravel-sortable example snippets
Schema::table('addresses', function (Blueprint $table) {
$table->orderColumn('order');
// $table->dropOrderColumn('order'); // To drop the order column
});
use Hichxm\LaravelSortable\HasSortableColumn;
class Address extends Model
{
use HasSortableColumn;
}
class Address extends Model
{
use HasSortableColumn;
protected $sortableColumn = 'custom_order';
}
$addressOne = Address::find(1);
$addressTwo = Address::find(2);
$addressThree = Address::find(3);
Address::swapOrder($addressOne, $addressTwo); // Swap the order of the two addresses
Address::setOrder($addressOne, 2); // Set the order of the address
Address::setNewOrder([$addressOne, $addressTwo, $addressThree]); // Set the order of the addresses
$addressQuery = Address::query();
$addressQuery->ordered()->get(); // Get the addresses ordered
$addressQuery->ordered('desc')->get(); // Get the addresses ordered in descending order
$addressQuery->orderedDesc()->get(); // Get the addresses ordered in ascending order
$addressQuery->ordered('asc')->get(); // Get the addresses ordered in ascending order
$addressQuery->orderedAsc()->get(); // Get the addresses ordered in ascending order
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.