for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* 雪花算法 Trait
*
* @author herry@<[email protected]>
* @version 1.0
* @copyright © 2020 MuCTS.com All Rights Reserved.
*/
namespace MuCTS\Laravel\Snowflake\Models\Traits;
use MuCTS\Laravel\Snowflake\Facades\Snowflake as SnowflakeFacade;
* Trait Snowflake
* @package MuCTS\Laravel\Snowflake\Models\Traits
trait Snowflake
{
protected static function boolSnowflake()
static::saving(function ($model) {
if (is_null($model->getKey())) {
$model->setIncrementing(false);
$keyName = $model->getKeyName();
$id = SnowflakeFacade::next();
$model->setAttribute($keyName, $id);
}
});