Add EmptyNameValidator and ItemValidatorByName.

This commit is contained in:
2023-08-27 20:31:26 +03:00
parent 3ffc82ee7c
commit e057d2de27
5 changed files with 128 additions and 45 deletions
@@ -0,0 +1,21 @@
<?php
namespace App\Models\Validation\Validators;
use App\Models\Validation\Validators\Validator;
class EmptyNameValidator extends Validator {
private string $name;
protected Validator $nextValidator;
public function __construct(string $name, Validator $nextValidator)
{
$this->name = $name;
$this->nextValidator = $nextValidator;
}
public function isCurrentValid(): bool
{
return $this->name != "";
}
}
@@ -0,0 +1,25 @@
<?php
namespace App\Models\Validation\Validators;
use App\Models\Validation\Validators\Validator;
use App\Models\Item;
class ItemValidatorByName extends Validator {
private string $name;
protected Validator $nextValidator;
public function __construct(string $name, Validator $nextValidator)
{
$this->name = $name;
$this->nextValidator = $nextValidator;
}
public function isCurrentValid(): bool
{
$count = Item::where('name', $this->name)->count();
return $count != 0;
}
}