PHP code example of exileofaranei / laravel-list-ordering
1. Go to this page and download the library: Download exileofaranei/laravel-list-ordering 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/ */
exileofaranei / laravel-list-ordering example snippets
use ExileOfAranei\ListOrdering\Concerns\HasOrdering;
use ExileOfAranei\ListOrdering\Contracts\Orderable;
class Task extends Model implements Orderable
{
use HasOrdering;
public function orderingGroupColumns(): array
{
return ['board_id', 'column'];
}
}
class GalleryImage extends Model implements Orderable
{
use HasOrdering;
public function orderingGroupColumns(): array
{
return ['gallery_id'];
}
}
class LandingFeature extends Model implements Orderable
{
use HasOrdering;
public function orderingGroupColumns(): array
{
return [];
}
}
use ExileOfAranei\ListOrdering\Support\GroupKey;
// Insert a new task at the end of a board column.
$task->placeInto(GroupKey::of(['board_id' => 42, 'column' => 'todo']), $lastInColumn, null);
// Move it to a different column, between two existing tasks.
$task->placeInto(GroupKey::of(['board_id' => 42, 'column' => 'done']), $doneFirst, $doneSecond);
$task->placeAtEnd(GroupKey::of(['board_id' => 42, 'column' => 'todo']));
$task->placeAtStart(GroupKey::of(['board_id' => 42, 'column' => 'todo']));
$task->placeAfter($anchorTask); // target group is $anchorTask's group right now
$task->placeBefore($anchorTask);
$clone = new Task(['board_id' => 99, 'column' => 'todo']); // $clone's own, different group
$clone->cloneRankFrom($original);
use ExileOfAranei\ListOrdering\Support\BatchReorderer;
// $newOrderOfKeys is every primary key currently in the group, in the order
// the UI now wants them — e.g. straight from a SortableJS `onEnd` payload.
BatchReorderer::apply(Task::class, GroupKey::of(['board_id' => 42, 'column' => 'todo']), $newOrderOfKeys);
use ExileOfAranei\ListOrdering\Testing\AssertsOrderingIndex;
class TaskOrderingTest extends TestCase
{
use AssertsOrderingIndex;
public function test_ordering_index_matches(): void
{
$this->assertOrderingIndexMatches(Task::class);
}
}