gurgentil / laravel-eloquent-sequencer

A package that allows you to create and manage sequences on Eloquent models.
MIT License
156 stars 13 forks source link

Sequence cannot start with 0 #33

Closed niktsanov closed 2 years ago

niktsanov commented 3 years ago

Hello,

Thank you for the awesome package! We've stumbled accross an issue where if the initial_value is set to 0 and there are no records in the database, when trying to add a new one, we get:

Gurgentil\LaravelEloquentSequencer\Exceptions\SequenceValueOutOfBoundsException with message 'Sequence value `0` is out of bounds.'

Steps to reproduce:

  1. Change config/eloquentsequencer.php:
    'initial_value' => 0
  2. Clear the table for a specific model, in this case, let's assume the model is Theme
  3. Theme::factory()->create()

The issue comes from the fact that 0 here is always threated as an out-of-bound value. https://github.com/gurgentil/laravel-eloquent-sequencer/blob/fc3454e331ef5680e654778362efda6b08901d44/src/Traits/Sequenceable.php#L158-L165