-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
280 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Clubs; | ||
|
||
use App\Livewire\Forms\ClubForm; | ||
use App\Models\Club; | ||
use App\Models\Venue; | ||
use Illuminate\View\View; | ||
use Livewire\Attributes\Layout; | ||
use Livewire\Component; | ||
|
||
class Create extends Component | ||
{ | ||
public ClubForm $form; | ||
|
||
public function mount(Club $club): void | ||
{ | ||
$this->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(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Clubs; | ||
|
||
use App\Livewire\Forms\ClubForm; | ||
use App\Models\Club; | ||
use App\Models\Venue; | ||
use Illuminate\View\View; | ||
use Livewire\Attributes\Layout; | ||
use Livewire\Component; | ||
|
||
class Edit extends Component | ||
{ | ||
public ClubForm $form; | ||
|
||
public function mount(Club $club): void | ||
{ | ||
$this->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(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Clubs; | ||
|
||
use App\Models\Club; | ||
use Illuminate\View\View; | ||
use Livewire\Attributes\Layout; | ||
use Livewire\Component; | ||
use Livewire\WithPagination; | ||
|
||
class Index extends Component | ||
{ | ||
use WithPagination; | ||
|
||
#[Layout('layouts.app')] | ||
public function render(): View | ||
{ | ||
$clubs = Club::query() | ||
->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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Clubs; | ||
|
||
use App\Livewire\Forms\ClubForm; | ||
use App\Models\Club; | ||
use Illuminate\View\View; | ||
use Livewire\Attributes\Layout; | ||
use Livewire\Component; | ||
|
||
class Show extends Component | ||
{ | ||
public ClubForm $form; | ||
|
||
public function mount(Club $club): void | ||
{ | ||
$this->form->setClubModel($club); | ||
} | ||
|
||
#[Layout('layouts.app')] | ||
public function render(): View | ||
{ | ||
return view('livewire.club.show', ['club' => $this->form->clubModel]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Forms; | ||
|
||
use App\Models\Club; | ||
use Livewire\Form; | ||
|
||
class ClubForm extends Form | ||
{ | ||
public ?Club $clubModel; | ||
|
||
public ?string $name; | ||
|
||
public ?string $venue_id; | ||
|
||
public function rules(): array | ||
{ | ||
return [ | ||
'name' => '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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<x-crud.header>Clubs</x-crud.header> | ||
|
||
<div class="w-full"> | ||
<x-crud.subheader back-route="clubs.index">Create a new clubs</x-crud.subheader> | ||
|
||
<x-crud.content class="mt-8 max-w-xl"> | ||
<form method="POST" wire:submit="save" role="form" enctype="multipart/form-data"> | ||
@csrf | ||
@include('livewire.club.form') | ||
</form> | ||
</x-crud.content> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<x-crud.header>Clubs</x-crud.header> | ||
|
||
<div class="w-full"> | ||
<x-crud.subheader back-route="clubs.index">Update the {{ $form->name }} club</x-crud.subheader> | ||
|
||
<x-crud.content class="mt-8 max-w-xl"> | ||
<form method="POST" wire:submit="save" role="form" enctype="multipart/form-data"> | ||
{{ method_field('PATCH') }} | ||
@csrf | ||
@include('livewire.club.form') | ||
</form> | ||
</x-crud.content> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<div class="space-y-6"> | ||
<div> | ||
<x-input-label for="name" value="Name" /> | ||
<x-text-input wire:model="form.name" id="name" name="name" type="text" class="mt-1 block w-full" | ||
autocomplete="name" placeholder="Club's name" /> | ||
@error('form.name') | ||
<x-input-error class="mt-2" :messages="$message" /> | ||
@enderror | ||
</div> | ||
<div> | ||
<x-input-label for="venue_id" value="Venue" /> | ||
<x-select-input wire:model="form.venue_id" id="venue_id" name="venue_id" class="mt-1 block w-full" | ||
:options="$venues" placeholder="Choose a venue" /> | ||
@error('form.venue_id') | ||
<x-input-error class="mt-2" :messages="$message" /> | ||
@enderror | ||
</div> | ||
|
||
<div class="flex items-center gap-4"> | ||
<x-primary-button>Save</x-primary-button> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<x-crud.header>Clubs</x-crud.header> | ||
|
||
<div class="w-full"> | ||
<x-crud.subheader add-route="clubs.create" class="mb-4"> | ||
A list of all the clubs in the system | ||
</x-crud.subheader> | ||
<x-crud.content> | ||
<x-crud.index.table columns="name,venue"> | ||
@foreach ($clubs as $club) | ||
<x-crud.index.row row-key="{{ $club->getKey() }}"> | ||
<x-crud.index.cell>{{ $club->name }}</x-crud.index.cell> | ||
<x-crud.index.cell>{{ $club->venue->name }}</x-crud.index.cell> | ||
<x-crud.index.cell class="flex gap-1 pl-2 pr-0 font-medium"> | ||
<x-crud.index.show-button route="clubs.show" :model="$club" /> | ||
<x-crud.index.edit-button route="clubs.edit" :model="$club" /> | ||
<x-crud.index.delete-button :model="$club"> | ||
Are you sure you want to delete the {{ $club->name }} club? | ||
</x-crud.index.delete-button> | ||
</x-crud.index.cell> | ||
</x-crud.index.row> | ||
@endforeach | ||
</x-crud.index.table> | ||
|
||
<div class="mt-4 px-4"> | ||
{!! $clubs->withQueryString()->links() !!} | ||
</div> | ||
</x-crud.content> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<x-crud.header>Clubs</x-crud.header> | ||
|
||
<div class="w-full"> | ||
<x-crud.subheader back-route="clubs.index">Details of the {{ $club->name }} club</x-crud.subheader> | ||
<x-crud.content> | ||
<x-crud.show.table> | ||
<x-crud.show.model-field label="Name">{{ $club->name }}</x-crud.show.model-field> | ||
<x-crud.show.model-field label="Venue">{{ $club->venue->name }}</x-crud.show.model-field> | ||
</x-crud.show.table> | ||
</x-crud.content> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters