Skip to content

Commit

Permalink
fix trait ulid
Browse files Browse the repository at this point in the history
  • Loading branch information
riipandi committed Mar 3, 2020
1 parent 56ff0c5 commit b69b0c2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Traits/HasUlidKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ trait HasUlidKey
public static function bootHasUlidKey()
{
static::creating(function ($model) {

$ulidFieldName = $model->getUlidFieldName();
$ulidLowerCase = $model->getUlidLowerCase();

if (empty($model->{$ulidFieldName})) {
$model->{$ulidFieldName} = self::generateUlid();
$model->{$ulidFieldName} = self::generateUlid($ulidLowerCase);
}

});
}

Expand Down Expand Up @@ -42,8 +46,8 @@ public static function findByUlid($ulid)
return static::byUlid($ulid)->first();
}

protected static function generateUlid()
protected static function generateUlid($lowercase = false)
{
return (string) \Ulid\Ulid::generate(self::getUlidLowerCase());
return (string) \Ulid\Ulid::generate($lowercase);
}
}

0 comments on commit b69b0c2

Please sign in to comment.