-
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
12 changed files
with
316 additions
and
2 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,52 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Forms; | ||
|
||
use App\Models\Team; | ||
use Livewire\Form; | ||
|
||
class TeamForm extends Form | ||
{ | ||
public ?Team $teamModel; | ||
|
||
public ?string $club_id; | ||
|
||
public ?string $clubName; | ||
|
||
public ?string $name; | ||
|
||
public ?string $venue_id; | ||
|
||
public function rules(): array | ||
{ | ||
return [ | ||
'club_id' => 'required|uuid|exists:clubs,id', | ||
'name' => 'required|string', | ||
'venue_id' => 'string|uuid|exists:venues,id', | ||
]; | ||
} | ||
|
||
public function setTeamModel(Team $teamModel): void | ||
{ | ||
$this->teamModel = $teamModel; | ||
|
||
$this->club_id = $this->teamModel->club_id; | ||
$this->clubName = $this->teamModel->club?->name; | ||
$this->name = $this->teamModel->name; | ||
$this->venue_id = $this->teamModel->venue_id; | ||
} | ||
|
||
public function store(): void | ||
{ | ||
$this->teamModel->create($this->validate()); | ||
|
||
$this->reset(); | ||
} | ||
|
||
public function update(): void | ||
{ | ||
$this->teamModel->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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Teams; | ||
|
||
use App\Livewire\Forms\TeamForm; | ||
use App\Models\Club; | ||
use App\Models\Team; | ||
use App\Models\Venue; | ||
use Illuminate\View\View; | ||
use Livewire\Attributes\Layout; | ||
use Livewire\Component; | ||
|
||
class Create extends Component | ||
{ | ||
public TeamForm $form; | ||
|
||
public function mount(Team $team): void | ||
{ | ||
$this->form->setTeamModel($team); | ||
} | ||
|
||
public function save(): void | ||
{ | ||
$this->form->store(); | ||
|
||
$this->redirectRoute('teams.index', navigate: true); | ||
} | ||
|
||
#[Layout('layouts.app')] | ||
public function render(): View | ||
{ | ||
return view('livewire.team.create', [ | ||
'clubs' => Club::query()->orderBy('name')->get(), | ||
'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,37 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Teams; | ||
|
||
use App\Livewire\Forms\TeamForm; | ||
use App\Models\Club; | ||
use App\Models\Team; | ||
use App\Models\Venue; | ||
use Illuminate\View\View; | ||
use Livewire\Attributes\Layout; | ||
use Livewire\Component; | ||
|
||
class Edit extends Component | ||
{ | ||
public TeamForm $form; | ||
|
||
public function mount(Team $team): void | ||
{ | ||
$this->form->setTeamModel($team); | ||
} | ||
|
||
public function save(): void | ||
{ | ||
$this->form->update(); | ||
|
||
$this->redirectRoute('teams.index', navigate: true); | ||
} | ||
|
||
#[Layout('layouts.app')] | ||
public function render(): View | ||
{ | ||
return view('livewire.team.edit', [ | ||
'clubs' => Club::query()->orderBy('name')->get(), | ||
'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,61 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Teams; | ||
|
||
use App\Models\Club; | ||
use App\Models\Team; | ||
use Illuminate\View\View; | ||
use Livewire\Attributes\Layout; | ||
use Livewire\Attributes\On; | ||
use Livewire\Component; | ||
use Livewire\WithPagination; | ||
|
||
class Index extends Component | ||
{ | ||
use WithPagination; | ||
|
||
public string $clubId; | ||
|
||
public array $filters; | ||
|
||
public function mount(): void | ||
{ | ||
$clubs = Club::query()->orderBy('name')->get(); | ||
$this->clubId = $clubs->first()->getKey(); | ||
|
||
$this->filters = [ | ||
'clubs' => [ | ||
'label' => 'Clubs', | ||
'options' => $clubs, | ||
'currentOption' => $this->clubId, | ||
'event' => 'club-selected', | ||
], | ||
]; | ||
} | ||
|
||
#[Layout('layouts.app')] | ||
public function render(): View | ||
{ | ||
$teams = Team::query() | ||
->where('club_id', $this->clubId) | ||
->with(['club', 'venue']) | ||
->orderBy('name') | ||
->simplePaginate(10); | ||
|
||
return view('livewire.team.index', compact('teams')) | ||
->with('i', $this->getPage() * $teams->perPage()); | ||
} | ||
|
||
public function delete(Team $team): void | ||
{ | ||
$team->delete(); | ||
|
||
$this->redirectRoute('teams.index', navigate: true); | ||
} | ||
|
||
#[On('club-selected')] | ||
public function setCurrentClub($clubId): void | ||
{ | ||
$this->clubId = $clubId; | ||
} | ||
} |
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\Teams; | ||
|
||
use App\Livewire\Forms\TeamForm; | ||
use App\Models\Team; | ||
use Illuminate\View\View; | ||
use Livewire\Attributes\Layout; | ||
use Livewire\Component; | ||
|
||
class Show extends Component | ||
{ | ||
public TeamForm $form; | ||
|
||
public function mount(Team $team): void | ||
{ | ||
$this->form->setTeamModel($team); | ||
} | ||
|
||
#[Layout('layouts.app')] | ||
public function render(): View | ||
{ | ||
return view('livewire.team.show', ['team' => $this->form->teamModel]); | ||
} | ||
} |
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>Teams</x-crud.header> | ||
|
||
<div class="w-full"> | ||
<x-crud.subheader back-route="teams.index">Create a new team</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.team.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>Teams</x-crud.header> | ||
|
||
<div class="w-full"> | ||
<x-crud.subheader back-route="teams.index">Update the {{ $this->form->teamModel->name }} team</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.team.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,35 @@ | ||
<div class="space-y-6"> | ||
<div> | ||
<x-input-label for="club_id" value="Club" /> | ||
@empty($form->club_id) | ||
<x-select-input wire:model="form.club_id" id="club_id" name="club_id" class="mt-1 block w-full" | ||
:options="$clubs" placeholder="Choose a club" /> | ||
@else | ||
<x-text-input wire:model="form.clubName" id="club_id" name="club_id" type="text" | ||
class="mt-1 block w-full" disabled /> | ||
@endempty | ||
@error('form.club_id') | ||
<x-input-error class="mt-2" :messages="$message" /> | ||
@enderror | ||
</div> | ||
<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="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,27 @@ | ||
<x-crud.header>Teams</x-crud.header> | ||
|
||
<div class="w-full"> | ||
<x-crud.subheader add-route="teams.create" class="mb-4">A list of all the teams in the system</x-crud.subheader> | ||
<livewire:filters :filters="$filters"/> | ||
<x-crud.content> | ||
<x-crud.index.table columns="name,venue"> | ||
@foreach ($teams as $team) | ||
<x-crud.index.row row-key="{{ $team->getKey() }}"> | ||
<x-crud.index.cell>{{ $team->name }}</x-crud.index.cell> | ||
<x-crud.index.cell>{{ $team->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="teams.show" :model="$team" /> | ||
<x-crud.index.edit-button route="teams.edit" :model="$team" /> | ||
<x-crud.index.delete-button :model="$team"> | ||
Are you sure you want to delete team {{ $team->name }}?" | ||
</x-crud.index.delete-button> | ||
</x-crud.index.cell> | ||
</x-crud.index.row> | ||
@endforeach | ||
</x-crud.index.table> | ||
|
||
<div class="mt-4 px-4"> | ||
{!! $teams->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>Teams</x-crud.header> | ||
|
||
<div class="w-full"> | ||
<x-crud.subheader back-route="teams.index">Details of the {{ $team->name }} team</x-crud.subheader> | ||
<x-crud.content> | ||
<x-crud.show.table> | ||
<x-crud.show.model-field label="Club">{{ $team->club->name }}</x-crud.show.model-field> | ||
<x-crud.show.model-field label="Name">{{ $team->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