mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
tags creation added
This commit is contained in:
34
app/Rules/TagUniqueRule.php
Normal file
34
app/Rules/TagUniqueRule.php
Normal 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]));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user