PHP code example of gurgentil / laravel-eloquent-sequencer

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

    

gurgentil / laravel-eloquent-sequencer example snippets


return [
    'column_name' => 'position',
    'initial_value' => 1,
    'strategy' => 'always',
];

protected static $sequenceable = 'order';

protected static $sequenceableKeys = [
    'task_list_id',
];

protected static $sequenceableKeys = [
    'commentable_id',
    'commentable_type',
];

Task::create([
    'position' => 1,
    'task_list_id' => 1,
]);

Task::create(['task_list_id' => 1]);

$task->update(['position' => 4]);

$task->delete();

$value = $task->getSequenceValue();

$columnName = Task::getSequenceColumnName();

$task->withoutSequencing()->update(['position' => 3]);

$task->withoutSequencing()->delete();

$tasks = Task::sequenced()->get();
bash
php artisan vendor:publish --provider="Gurgentil\LaravelEloquentSequencer\LaravelEloquentSequencerServiceProvider"
 php
use Gurgentil\LaravelEloquentSequencer\Traits\Sequenceable;
use Illuminate\Database\Eloquent\Model;

class Task extends Model
{
    use Sequenceable;

    protected $fillable = [
        'position',
    ];
    
    protected static $sequenceableKeys = [
        'task_list_id',
    ];

    public function taskList()
    {
        return $this->belongsTo(TaskList::class);
    }
}
bash
php artisan sequence:populate \\App\\Task
bash
php artisan sequence:flush \\App\\Task