*/ protected $fillable = [ 'name', 'signs', 'address', 'city', 'postcode', 'latitude', 'longitude', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ '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 self::assertFieldIsUnique('name', $model->name); }); static::updating(function (self $model) { // * ASSERTIONS self::assertFieldIsUnique('name', $model->name, $model->id); }); } /** * Asserts using validation that the field is unique. * * @param string $nameField * @param string $valueField * @param integer|null $id * @return void */ private static function assertFieldIsUnique(string $nameField, string $valueField, ?int $id = null) { $table = (new self())->getTable(); ToolboxHelper::assertFieldIsUnique($table, $nameField, $valueField, $id); } }