tags creation added

This commit is contained in:
HolgerHatGarKeineNode
2023-03-17 13:36:59 +01:00
parent f87bf151da
commit d7ff201301
8 changed files with 220 additions and 34 deletions

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Rules;
use App\Models\Tag;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
class TagUniqueRule implements ValidationRule
{
/**
* Indicates whether the rule should be implicit.
*
* @var bool
*/
public $implicit = true;
public function __construct(public string $type = 'library_item')
{
}
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$tag = Tag::findFromString($value, $this->type);
if ($tag) {
$fail(__('Tags must be unique', ['attribute' => $attribute]));
}
}
}