PHP code example of leparking / laravel-sortable

1. Go to this page and download the library: Download leparking/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/ */

    

leparking / laravel-sortable example snippets


    'providers' => [
        // ...
        LeParking\Sortable\SortableServiceProvider::class,
    ],

return [
     // Name of the column that will store the position.
    'column' => 'position',

     // If set to true, new models will be inserted at the first position.
    'insert_first' => false,

     // A column name or an array of columns names to group sortable models.
    'group_by' => false,
];

use Illuminate\Database\Eloquent\Model;
use LeParking\Sortable\Sortable;
use LeParking\Sortable\SortableTrait;

class Book extends Model implements Sortable
{
    use SortableTrait;

    // Optional property to override default settings.
    protected $sortable = [
        // ...
    ];
}


Schema::create('books', function($table) {
    $table->integer('position')->unsigned();
});

$book = Book::create();
echo $book->position; // 1

$book2 = Book::create();
echo $book2->position; // 2

$books = Book::ordered();
$books = Book::ordered('desc');
sh
php artisan vendor:publish