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 - + Clubs diff --git a/resources/views/livewire/club/create.blade.php b/resources/views/livewire/club/create.blade.php new file mode 100644 index 00000000..74f76cd3 --- /dev/null +++ b/resources/views/livewire/club/create.blade.php @@ -0,0 +1,12 @@ +Clubs + +
+ Create a new clubs + + +
+ @csrf + @include('livewire.club.form') +
+
+
diff --git a/resources/views/livewire/club/edit.blade.php b/resources/views/livewire/club/edit.blade.php new file mode 100644 index 00000000..53f80a4b --- /dev/null +++ b/resources/views/livewire/club/edit.blade.php @@ -0,0 +1,13 @@ +Clubs + +
+ Update the {{ $form->name }} club + + +
+ {{ method_field('PATCH') }} + @csrf + @include('livewire.club.form') +
+
+
diff --git a/resources/views/livewire/club/form.blade.php b/resources/views/livewire/club/form.blade.php new file mode 100644 index 00000000..6c4abc9b --- /dev/null +++ b/resources/views/livewire/club/form.blade.php @@ -0,0 +1,22 @@ +
+
+ + + @error('form.name') + + @enderror +
+
+ + + @error('form.venue_id') + + @enderror +
+ +
+ Save +
+
diff --git a/resources/views/livewire/club/index.blade.php b/resources/views/livewire/club/index.blade.php new file mode 100644 index 00000000..4794b9ad --- /dev/null +++ b/resources/views/livewire/club/index.blade.php @@ -0,0 +1,28 @@ +Clubs + +
+ + A list of all the clubs in the system + + + + @foreach ($clubs as $club) + + {{ $club->name }} + {{ $club->venue->name }} + + + + + Are you sure you want to delete the {{ $club->name }} club? + + + + @endforeach + + +
+ {!! $clubs->withQueryString()->links() !!} +
+
+
diff --git a/resources/views/livewire/club/show.blade.php b/resources/views/livewire/club/show.blade.php new file mode 100644 index 00000000..4184a892 --- /dev/null +++ b/resources/views/livewire/club/show.blade.php @@ -0,0 +1,11 @@ +Clubs + +
+ Details of the {{ $club->name }} club + + + {{ $club->name }} + {{ $club->venue->name }} + + +
diff --git a/routes/web.php b/routes/web.php index ce957f9f..72b36619 100644 --- a/routes/web.php +++ b/routes/web.php @@ -26,7 +26,12 @@ Route::get('/divisions/update/{division}', \App\Livewire\Divisions\Edit::class)->name('divisions.edit'); Route::view('fixtures', 'fixtures')->name('fixtures'); - Route::view('clubs', 'clubs')->name('clubs'); + + Route::get('/clubs', \App\Livewire\Clubs\Index::class)->name('clubs.index'); + Route::get('/clubs/create', \App\Livewire\Clubs\Create::class)->name('clubs.create'); + Route::get('/clubs/show/{club}', \App\Livewire\Clubs\Show::class)->name('clubs.show'); + Route::get('/clubs/update/{club}', \App\Livewire\Clubs\Edit::class)->name('clubs.edit'); + Route::view('teams', 'teams')->name('teams'); Route::view('venues', 'venues')->name('venues'); });