1. Go to this page and download the library: Download sudo520/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/ */
sudo520 / laravel-sortable example snippets
use Sudo520\LaravelSortable\Sortable;
class MyModel extends Eloquent
{
use Sortable;
protected $fillable = [
...
'sort_index',
...
];
...
}
class CreateMyModelsTable extends Migration
{
public function up()
{
Schema::create('my_models', function (Blueprint $table) {
...
$table->unsignedInteger('sort_index');
...
});
}
public function down()
{
Schema::dropIfExists('my_models');
}
}
use Sudo520\LaravelSortable\Sortable;
class MyModel extends Eloquent
{
use Sortable;
public $sortIndexColumn = 'order';
...
}
use Sudo520\LaravelSortable\Sortable;
class MyModel extends Eloquent
{
use Sortable;
public $setSortIndexOnCreating = false;
...
}
use Sudo520\LaravelSortable\Sortable;
class Post extends Eloquent
{
use Sortable;
public $sortingParentColumn = 'user_id';
...
}
use Sudo520\LaravelSortable\Sortable;
class MyModel extends Eloquent
{
use Sortable;
public $startSortingFrom = 0;
...
}
MyModel::create([...]); // sort_index 0
MyModel::create([...]); // sort_index 1
MyModel::create([...]); // sort_index 2