Skip to content

Commit

Permalink
automatically set to false when saving. (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesscarlos authored and kra committed Dec 30, 2019
1 parent b02e837 commit 3bc3ccc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $id = $snowflake->next();
```
# Usage with Eloquent
Add the `Kra8\Snowflake\HasSnowflakePrimary` trait to your Eloquent model.
This trait make type `snowflake` of primary key. Don't forget to set the Auto increment property to false.
This trait make type `snowflake` of primary key. Trait will automatically set $incrementing property to false.

``` php
<?php
Expand All @@ -54,13 +54,6 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasSnowflakePrimary, Notifiable;

/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public $incrementing = false;
}
```

Expand Down
1 change: 1 addition & 0 deletions src/HasSnowflakePrimary.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static function bootHasSnowflakePrimary()
{
static::saving(function ($model) {
if (is_null($model->getKey())) {
$model->setIncrementing(false);
$keyName = $model->getKeyName();
$id = app(Snowflake::class)->next();
$model->setAttribute($keyName, $id);
Expand Down

0 comments on commit 3bc3ccc

Please sign in to comment.