diff --git a/app/Livewire/Clubs/Create.php b/app/Livewire/Clubs/Create.php new file mode 100644 index 00000000..302af313 --- /dev/null +++ b/app/Livewire/Clubs/Create.php @@ -0,0 +1,35 @@ +form->setClubModel($club); + } + + public function save(): void + { + $this->form->store(); + + $this->redirectRoute('clubs.index', navigate: true); + } + + #[Layout('layouts.app')] + public function render(): View + { + return view('livewire.club.create', [ + 'venues' => Venue::query()->orderBy('name')->get(), + ]); + } +} diff --git a/app/Livewire/Clubs/Edit.php b/app/Livewire/Clubs/Edit.php new file mode 100644 index 00000000..bcf4e14f --- /dev/null +++ b/app/Livewire/Clubs/Edit.php @@ -0,0 +1,35 @@ +form->setClubModel($club); + } + + public function save(): void + { + $this->form->update(); + + $this->redirectRoute('clubs.index', navigate: true); + } + + #[Layout('layouts.app')] + public function render(): View + { + return view('livewire.club.edit', [ + 'venues' => Venue::query()->orderBy('name')->get(), + ]); + } +} diff --git a/app/Livewire/Clubs/Index.php b/app/Livewire/Clubs/Index.php new file mode 100644 index 00000000..7b3eaad0 --- /dev/null +++ b/app/Livewire/Clubs/Index.php @@ -0,0 +1,33 @@ +orderBy('name') + ->with('venue') + ->simplePaginate(10); + + return view('livewire.club.index', compact('clubs')) + ->with('i', $this->getPage() * $clubs->perPage()); + } + + public function delete(Club $club): void + { + $club->delete(); + + $this->redirectRoute('clubs.index', navigate: true); + } +} diff --git a/app/Livewire/Clubs/Show.php b/app/Livewire/Clubs/Show.php new file mode 100644 index 00000000..1e757602 --- /dev/null +++ b/app/Livewire/Clubs/Show.php @@ -0,0 +1,25 @@ +form->setClubModel($club); + } + + #[Layout('layouts.app')] + public function render(): View + { + return view('livewire.club.show', ['club' => $this->form->clubModel]); + } +} diff --git a/app/Livewire/Forms/ClubForm.php b/app/Livewire/Forms/ClubForm.php new file mode 100644 index 00000000..f7edf4cd --- /dev/null +++ b/app/Livewire/Forms/ClubForm.php @@ -0,0 +1,45 @@ + 'required|string', + 'venue_id' => 'string|uuid|exists:venues,id', + ]; + } + + public function setClubModel(Club $clubModel): void + { + $this->clubModel = $clubModel; + + $this->name = $this->clubModel->name; + $this->venue_id = $this->clubModel->venue_id; + } + + public function store(): void + { + $this->clubModel->create($this->validate()); + + $this->reset(); + } + + public function update(): void + { + $this->clubModel->update($this->validate()); + + $this->reset(); + } +} diff --git a/app/Models/Club.php b/app/Models/Club.php index cca87a75..1e88d906 100644 --- a/app/Models/Club.php +++ b/app/Models/Club.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Models\Contracts\Selectable; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -14,7 +15,7 @@ * @property-read Collection $teams * @property-read ?Venue $venue */ -class Club extends Model +class Club extends Model implements Selectable { use HasFactory, HasUuids; @@ -34,4 +35,9 @@ public function venue(): BelongsTo { return $this->belongsTo(Venue::class); } + + public function getName(): string + { + return $this->name; + } } diff --git a/app/Models/Venue.php b/app/Models/Venue.php index c87187b6..46546acb 100644 --- a/app/Models/Venue.php +++ b/app/Models/Venue.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Models\Contracts\Selectable; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -13,7 +14,7 @@ * @property-read Collection $clubs * @property-read Collection teams */ -class Venue extends Model +class Venue extends Model implements Selectable { use HasFactory, HasUuids; @@ -31,4 +32,9 @@ public function teams(): HasMany { return $this->hasMany(Team::class); } + + public function getName(): string + { + return $this->name; + } } diff --git a/resources/views/components/navigation.blade.php b/resources/views/components/navigation.blade.php index a63444d5..198f9e01 100644 --- a/resources/views/components/navigation.blade.php +++ b/resources/views/components/navigation.blade.php @@ -12,7 +12,7 @@ Divisions