1. Go to this page and download the library: Download james.xue/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/ */
james.xue / laravel-sortable example snippets
use James\Sortable\SortableTrait;
use James\Sortable\Sortable;
class MyModel extends Eloquent implements Sortable
{
use SortableTrait;
public $sortable = [
'sort_field' => 'view',
'sort_when_creating' => true,
];
...
}
$myModel = new MyModel();
$myModel->save(); // sort_field for this record will be set to 1
$myModel = new MyModel();
$myModel->save(); // sort_field for this record will be set to 2
$myModel = new MyModel();
$myModel->save(); // sort_field for this record will be set to 3
$myModel = new MyModel();
$myModel->where('id', $id)->first()->move('up'); // up、down、top、end
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.