mirror of https://github.com/pixelfed/pixelfed
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
343 B
PHP
20 lines
343 B
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use App\Services\SnowflakeService;
|
|
|
|
trait HasSnowflakePrimary
|
|
{
|
|
public static function bootHasSnowflakePrimary()
|
|
{
|
|
static::saving(function ($model) {
|
|
if (is_null($model->getKey())) {
|
|
$keyName = $model->getKeyName();
|
|
$id = SnowflakeService::next();
|
|
$model->setAttribute($keyName, $id);
|
|
}
|
|
});
|
|
}
|
|
}
|