mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-04 15:32:35 +00:00
#591 - tags
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
|
||||
use App\Models\Tag;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
@ -16,10 +17,13 @@ class CreateTag
|
||||
*/
|
||||
public function create(User $user, array $input): Tag
|
||||
{
|
||||
Validator::make($input, self::rules())->validate();
|
||||
|
||||
$tag = Tag::query()
|
||||
->where('project_id', $user->current_project_id)
|
||||
->where('name', $input['name'])
|
||||
->first();
|
||||
|
||||
if ($tag) {
|
||||
throw ValidationException::withMessages([
|
||||
'name' => ['Tag with this name already exists.'],
|
||||
@ -47,7 +51,7 @@ public static function rules(): array
|
||||
],
|
||||
'color' => [
|
||||
'required',
|
||||
Rule::in(config('core.tag_colors')),
|
||||
Rule::in(config('core.colors')),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Actions\Tag;
|
||||
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class EditTag
|
||||
@ -12,6 +13,8 @@ class EditTag
|
||||
*/
|
||||
public function edit(Tag $tag, array $input): void
|
||||
{
|
||||
Validator::make($input, self::rules())->validate();
|
||||
|
||||
$tag->name = $input['name'];
|
||||
$tag->color = $input['color'];
|
||||
|
||||
@ -29,7 +32,7 @@ public static function rules(): array
|
||||
],
|
||||
'color' => [
|
||||
'required',
|
||||
Rule::in(config('core.tag_colors')),
|
||||
Rule::in(config('core.colors')),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
use App\Models\Server;
|
||||
use App\Models\Site;
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SyncTags
|
||||
@ -12,8 +13,10 @@ class SyncTags
|
||||
/**
|
||||
* @param array<string, mixed> $input
|
||||
*/
|
||||
public function sync(array $input): void
|
||||
public function sync(int $projectId, array $input): void
|
||||
{
|
||||
Validator::make($input, self::rules($projectId))->validate();
|
||||
|
||||
/** @var Server|Site $taggable */
|
||||
$taggable = $input['taggable_type']::findOrFail($input['taggable_id']);
|
||||
|
||||
|
Reference in New Issue
Block a user