distance = 0; } /** * Map attribute names to enum classes. * * @var array */ protected $enumCasts = [ 'signs' => SignsEnum::class, ]; /** * Perform any actions required after the model boots. * * @return void */ protected static function booted() { // * EVENT CLOSURES. static::creating(function (self $model) { // * ASSERTIONS static::assertNameIsUnique($model->name); }); static::updating(function (self $model) { // * ASSERTIONS static::assertNameIsUnique($model->name, $model->id); }); } // * METHODS /** * Asserts using validation that the name is unique * * @param mixed $name * @param integer|null $id * @return void */ private static function assertNameIsUnique($name, ?int $id = null) { $table = (new self())->getTable(); ToolboxHelper::assertFieldIsUnique($table, 'name', $name, $id); } }