From 063d420db24cf3d93f188ed7025475acc1dca723 Mon Sep 17 00:00:00 2001 From: David Buday Date: Mon, 18 Nov 2024 09:00:07 +0000 Subject: [PATCH] chore: svg + new validations --- app/Livewire/Images/Registry/Create.php | 27 +++++++++-------- app/Livewire/Images/Registry/Show.php | 32 ++++++++++++--------- resources/views/components/navbar.blade.php | 16 ++++++++++- 3 files changed, 48 insertions(+), 27 deletions(-) diff --git a/app/Livewire/Images/Registry/Create.php b/app/Livewire/Images/Registry/Create.php index 0a0866589..144ceb76e 100644 --- a/app/Livewire/Images/Registry/Create.php +++ b/app/Livewire/Images/Registry/Create.php @@ -2,24 +2,26 @@ namespace App\Livewire\Images\Registry; +use Livewire\Attributes\Validate; use App\Models\DockerRegistry; use Livewire\Component; class Create extends Component { + #[Validate('required|string|max:255')] public string $name = ''; - public string $type = 'docker_hub'; - public ?string $url = null; - public ?string $username = null; - public ?string $token = null; - protected $rules = [ - 'name' => 'required|string|max:255', - 'type' => 'required|string', - 'url' => 'nullable|string|max:255', - 'username' => 'nullable|string|max:255', - 'token' => 'nullable|string', - ]; + #[Validate('required|string')] + public string $type = 'docker_hub'; + + #[Validate('nullable|string|max:255')] + public ?string $url = null; + + #[Validate('nullable|string|max:255')] + public ?string $username = null; + + #[Validate('nullable|string')] + public ?string $token = null; public function getRegistryTypesProperty() { @@ -28,6 +30,7 @@ class Create extends Component public function submit() { + // Validation is automatically applied based on attributes $this->validate(); DockerRegistry::create([ @@ -47,4 +50,4 @@ class Create extends Component { return view('livewire.images.registry.create'); } -} +}; diff --git a/app/Livewire/Images/Registry/Show.php b/app/Livewire/Images/Registry/Show.php index 90069f571..e7f464a21 100644 --- a/app/Livewire/Images/Registry/Show.php +++ b/app/Livewire/Images/Registry/Show.php @@ -3,24 +3,27 @@ namespace App\Livewire\Images\Registry; use App\Models\DockerRegistry; +use Livewire\Attributes\Validate; use Livewire\Component; class Show extends Component { public DockerRegistry $registry; - public string $name = ''; - public string $type = ''; - public ?string $url = null; - public ?string $username = null; - public ?string $token = null; - protected $rules = [ - 'name' => 'required|string|max:255', - 'type' => 'required|string', - 'url' => 'nullable|string|max:255', - 'username' => 'nullable|string|max:255', - 'token' => 'nullable|string', - ]; + #[Validate('required|string|max:255')] + public string $name = ''; + + #[Validate('required|string')] + public string $type = ''; + + #[Validate('nullable|string|max:255')] + public ?string $url = null; + + #[Validate('nullable|string|max:255')] + public ?string $username = null; + + #[Validate('nullable|string')] + public ?string $token = null; public function mount(DockerRegistry $registry) { @@ -39,6 +42,7 @@ class Show extends Component public function updateRegistry() { + // Validation is automatically applied based on attributes $this->validate(); $this->registry->update([ @@ -58,7 +62,7 @@ class Show extends Component $this->registry->applications() ->update([ 'docker_registry_id' => null, - 'docker_use_custom_registry' => false + 'docker_use_custom_registry' => false, ]); $this->registry->delete(); @@ -79,4 +83,4 @@ class Show extends Component || $this->username !== $this->registry->username || $this->token !== $this->registry->token; } -} +}; diff --git a/resources/views/components/navbar.blade.php b/resources/views/components/navbar.blade.php index b80e44ad5..d3839b8f3 100644 --- a/resources/views/components/navbar.blade.php +++ b/resources/views/components/navbar.blade.php @@ -150,7 +150,21 @@ class="{{ request()->is('images*') ? 'menu-item-active menu-item' : 'menu-item' }}" href="{{ route('images.images.index') }}" - + + + + + + + + + + + + + Images