Skip to content

Commit

Permalink
Added Venue CRUD
Browse files Browse the repository at this point in the history
  • Loading branch information
troccoli committed Sep 3, 2024
1 parent bdeaca3 commit 7d2009d
Show file tree
Hide file tree
Showing 12 changed files with 244 additions and 5 deletions.
41 changes: 41 additions & 0 deletions app/Livewire/Forms/VenueForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Livewire\Forms;

use App\Models\Venue;
use Livewire\Form;

class VenueForm extends Form
{
public ?Venue $venueModel;

public ?string $name;

public function rules(): array
{
return [
'name' => 'required|string',
];
}

public function setVenueModel(Venue $venueModel): void
{
$this->venueModel = $venueModel;

$this->name = $this->venueModel->name;
}

public function store(): void
{
$this->venueModel->create($this->validate());

$this->reset();
}

public function update(): void
{
$this->venueModel->update($this->validate());

$this->reset();
}
}
32 changes: 32 additions & 0 deletions app/Livewire/Venues/Create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Livewire\Venues;

use App\Livewire\Forms\VenueForm;
use App\Models\Venue;
use Illuminate\View\View;
use Livewire\Attributes\Layout;
use Livewire\Component;

class Create extends Component
{
public VenueForm $form;

public function mount(Venue $venue): void
{
$this->form->setVenueModel($venue);
}

public function save(): void
{
$this->form->store();

$this->redirectRoute('venues.index', navigate: true);
}

#[Layout('layouts.app')]
public function render(): View
{
return view('livewire.venue.create');
}
}
32 changes: 32 additions & 0 deletions app/Livewire/Venues/Edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Livewire\Venues;

use App\Livewire\Forms\VenueForm;
use App\Models\Venue;
use Illuminate\View\View;
use Livewire\Attributes\Layout;
use Livewire\Component;

class Edit extends Component
{
public VenueForm $form;

public function mount(Venue $venue): void
{
$this->form->setVenueModel($venue);
}

public function save(): void
{
$this->form->update();

$this->redirectRoute('venues.index', navigate: true);
}

#[Layout('layouts.app')]
public function render(): View
{
return view('livewire.venue.edit');
}
}
30 changes: 30 additions & 0 deletions app/Livewire/Venues/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Livewire\Venues;

use App\Models\Venue;
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
{
$venues = Venue::simplePaginate(10);

return view('livewire.venue.index', compact('venues'))
->with('i', $this->getPage() * $venues->perPage());
}

public function delete(Venue $venue): void
{
$venue->delete();

$this->redirectRoute('venues.index', navigate: true);
}
}
25 changes: 25 additions & 0 deletions app/Livewire/Venues/Show.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Livewire\Venues;

use App\Livewire\Forms\VenueForm;
use App\Models\Venue;
use Illuminate\View\View;
use Livewire\Attributes\Layout;
use Livewire\Component;

class Show extends Component
{
public VenueForm $form;

public function mount(Venue $venue): void
{
$this->form->setVenueModel($venue);
}

#[Layout('layouts.app')]
public function render(): View
{
return view('livewire.venue.show', ['venue' => $this->form->venueModel]);
}
}
2 changes: 1 addition & 1 deletion resources/views/components/navigation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Teams
</x-responsive-nav-link>
<hr class="hidden md:block"/>
<x-responsive-nav-link :href="route('venues')" :active="request()->routeIs('venues')" wire:navigate>
<x-responsive-nav-link :href="route('venues.index')" :active="request()->routeIs('venues.*')" wire:navigate>
Venues
</x-responsive-nav-link>
<hr class="hidden md:block"/>
Expand Down
12 changes: 12 additions & 0 deletions resources/views/livewire/venue/create.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<x-crud.header>Venues</x-crud.header>

<div class="w-full">
<x-crud.subheader back-route="venues.index">Create a new venue</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.venue.form')
</form>
</x-crud.content>
</div>
13 changes: 13 additions & 0 deletions resources/views/livewire/venue/edit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<x-crud.header>Venues</x-crud.header>

<div class="w-full">
<x-crud.subheader back-route="venues.index">Update the {{ $this->form->venueModel->name }} venue</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.venue.form')
</form>
</x-crud.content>
</div>
13 changes: 13 additions & 0 deletions resources/views/livewire/venue/form.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<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="Name with full address"/>
@error('form.name')
<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>
25 changes: 25 additions & 0 deletions resources/views/livewire/venue/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<x-crud.header>Venues</x-crud.header>

<div class="w-full">
<x-crud.subheader add-route="venues.create" class="mb-4">A list of all the venues in the system</x-crud.subheader>
<x-crud.content>
<x-crud.index.table columns="name">
@foreach ($venues as $venue)
<x-crud.index.row row-key="{{ $venue->getKey() }}">
<x-crud.index.cell>{{ $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="venues.show" :model="$venue" />
<x-crud.index.edit-button route="venues.edit" :model="$venue" />
<x-crud.index.delete-button :model="$venue">
Are you sure you want to delete venue {{ $venue->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">
{!! $venues->withQueryString()->links() !!}
</div>
</x-crud.content>
</div>
10 changes: 10 additions & 0 deletions resources/views/livewire/venue/show.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<x-crud.header>Venues</x-crud.header>

<div class="w-full">
<x-crud.subheader back-route="venues.index">Details of the {{ $venue->name }} venue</x-crud.subheader>
<x-crud.content>
<x-crud.show.table>
<x-crud.show.model-field label="Name">{{ $venue->name }}</x-crud.show.model-field>
</x-crud.show.table>
</x-crud.content>
</div>
14 changes: 10 additions & 4 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
Route::get('/seasons/update/{season}', \App\Livewire\Seasons\Edit::class)->name('seasons.edit');

Route::get('/competitions', \App\Livewire\Competitions\Index::class)->name('competitions.index');
Route::get('/competitions/create', \App\Livewire\Competitions\Create::class)->name('competitions.create');
Route::get('/competitions/show/{competition}', \App\Livewire\Competitions\Show::class)->name('competitions.show');
Route::get('/competitions/update/{competition}', \App\Livewire\Competitions\Edit::class)->name('competitions.edit');
Route::get('/competitions/create',
\App\Livewire\Competitions\Create::class)->name('competitions.create');
Route::get('/competitions/show/{competition}',
\App\Livewire\Competitions\Show::class)->name('competitions.show');
Route::get('/competitions/update/{competition}',
\App\Livewire\Competitions\Edit::class)->name('competitions.edit');

Route::get('/divisions', \App\Livewire\Divisions\Index::class)->name('divisions.index');
Route::get('/divisions/create', \App\Livewire\Divisions\Create::class)->name('divisions.create');
Expand All @@ -37,7 +40,10 @@
Route::get('/teams/show/{team}', \App\Livewire\Teams\Show::class)->name('teams.show');
Route::get('/teams/update/{team}', \App\Livewire\Teams\Edit::class)->name('teams.edit');

Route::view('venues', 'venues')->name('venues');
Route::get('/venues', \App\Livewire\Venues\Index::class)->name('venues.index');
Route::get('/venues/create', \App\Livewire\Venues\Create::class)->name('venues.create');
Route::get('/venues/show/{venue}', \App\Livewire\Venues\Show::class)->name('venues.show');
Route::get('/venues/update/{venue}', \App\Livewire\Venues\Edit::class)->name('venues.edit');
});

Route::view('appointments', 'appointments')->name('appointments');
Expand Down

0 comments on commit 7d2009d

Please sign in to comment.