News

Create Model Sequences With the Eloquent Sequencer Package

Published
Create Model Sequences With the Eloquent Sequencer Package image

Eloquent Sequencer is a package by Gustavo R. Gentil for automatically sequencing your models when adding new records. This package makes it trivial to rearrange things like todos, cards, or lists of models.

Here’s an example from the readme demonstrating a task list that has many Task models:

use Gurgentil\LaravelEloquentSequencer\Traits\Sequenceable;
use Illuminate\Database\Eloquent\Model;
 
class Task extends Model
{
use Sequenceable;
 
protected static $fillable = [
'position',
];
 
protected static $sequenceableKeys = [
'task_list_id',
];
 
public function taskList()
{
return $this->belongsTo(TaskList::class);
}
}

Let’s say that you have a drag and drop interface for reordering tasks. You could call the following methods, and this package will automatically rearrange the sequence of tasks:

// Other items in the sequence will be rearranged
$task->update(['position' => 4]);
 
// Remaining tasks will be rearranged after removing a task
$task->delete();

Finally, you’d use the following method to get the sequenced list of tasks:

$tasks = Task::sequenced()->get();

Learn More

You can learn more about this package, get full installation instructions, and view the source code on GitHub at gurgentil/laravel-eloquent-sequencer.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Filed in

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
Image Dominant Color and HEIC Support in Laravel 13.24 image

Image Dominant Color and HEIC Support in Laravel 13.24

Read article
Official Laravel Zed Extension: LSP for PHP & Blade image

Official Laravel Zed Extension: LSP for PHP & Blade

Read article
Laravel Head: Manage Meta Tags, Open Graph, and JSON-LD image

Laravel Head: Manage Meta Tags, Open Graph, and JSON-LD

Read article
PhpStorm 2026.2 Released image

PhpStorm 2026.2 Released

Read article
Laravel Doctor: Diagnose Your App With One Artisan Command image

Laravel Doctor: Diagnose Your App With One Artisan Command

Read article
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article