From 4548be098a929e5a13328856cd071bc3f5e17812 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Sun, 26 Oct 2025 17:46:55 -0500 Subject: [PATCH] Allow admins to rename events. Closes #114 --- .../Controllers/Admin/EventController.php | 21 +++++- .../event/index-rename-event-modal.blade.php | 14 ++++ resources/views/admin/event/index.blade.php | 74 +++++++++++-------- routes/admin.php | 1 + .../Controllers/Admin/EventControllerTest.php | 20 +++++ 5 files changed, 99 insertions(+), 31 deletions(-) create mode 100644 resources/views/admin/event/index-rename-event-modal.blade.php diff --git a/app/Http/Controllers/Admin/EventController.php b/app/Http/Controllers/Admin/EventController.php index a00b154..91dd686 100644 --- a/app/Http/Controllers/Admin/EventController.php +++ b/app/Http/Controllers/Admin/EventController.php @@ -13,8 +13,12 @@ class EventController extends Controller public function index() { $events = Event::all(); + $renameModalXdata = ''; + foreach ($events as $event) { + $renameModalXdata .= 'showRenameModal_'.$event->id.': false, '; + } - return view('admin.event.index', compact('events')); + return view('admin.event.index', compact('events', 'renameModalXdata')); } public function store(Request $request) @@ -30,6 +34,21 @@ class EventController extends Controller return redirect()->route('admin.events.index')->with('success', 'Event created successfully'); } + public function update(Request $request, Event $event) + { + if ($request->name !== $event->name) { + $validated = request()->validate([ + 'name' => ['required', 'unique:events,name'], + ]); + + $event->update([ + 'name' => $validated['name'], + ]); + } + + return redirect()->route('admin.events.index')->with('success', 'Event renamed successfully'); + } + public function destroy(Request $request, Event $event) { if ($event->auditions()->count() > 0) { diff --git a/resources/views/admin/event/index-rename-event-modal.blade.php b/resources/views/admin/event/index-rename-event-modal.blade.php new file mode 100644 index 0000000..209e919 --- /dev/null +++ b/resources/views/admin/event/index-rename-event-modal.blade.php @@ -0,0 +1,14 @@ + + +Rename Event + + + + +
+ Update Event +
+ +
+
+
diff --git a/resources/views/admin/event/index.blade.php b/resources/views/admin/event/index.blade.php index 7189d22..e88e8d5 100644 --- a/resources/views/admin/event/index.blade.php +++ b/resources/views/admin/event/index.blade.php @@ -8,36 +8,50 @@ - - - @foreach($events as $event) - - {{ $event->name }}, {{ $event->auditions()->count() }} Auditions - -   - @if($event->auditions()->count() == 0) -
- @csrf - @method('DELETE') - -
- @endif +
+ @foreach($events as $event) + @php($currentRenameModalName = "showRenameModal_".$event->id) + @include('admin.event.index-rename-event-modal') + @endforeach + + + + @foreach($events as $event) + + + + {{ $event->name }} + +
+ {{ $event->auditions()->count() }} Auditions +
+ +   + @if($event->auditions()->count() == 0) +
+ @csrf + @method('DELETE') + +
+ @endif +
+ + @endforeach +
+ + + + + - - @endforeach - - - - - - - - - Create - - - - -
+ + Create + + + + + +
diff --git a/routes/admin.php b/routes/admin.php index 2690b80..642c40f 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -88,6 +88,7 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')-> Route::get('/', 'index')->name('admin.events.index'); Route::post('/', 'store')->name('admin.events.store'); Route::delete('/{event}', 'destroy')->name('admin.events.destroy'); + Route::patch('/{event}', 'update')->name('admin.events.update'); }); // Admin Rooms Routes diff --git a/tests/Feature/app/Http/Controllers/Admin/EventControllerTest.php b/tests/Feature/app/Http/Controllers/Admin/EventControllerTest.php index c639190..c9d02f3 100644 --- a/tests/Feature/app/Http/Controllers/Admin/EventControllerTest.php +++ b/tests/Feature/app/Http/Controllers/Admin/EventControllerTest.php @@ -79,6 +79,26 @@ describe('EventController::Store', function () { }); }); +describe('EventController::Update', function () { + beforeEach(function () { + $this->event = Event::factory()->create(); + }); + it('denies access to a non-admin user', function () { + $this->patch(route('admin.events.update', $this->event), [])->assertRedirect(route('home')); + actAsNormal(); + $this->patch(route('admin.events.update', $this->event), [])->assertRedirect(route('dashboard')); + actAsTab(); + $this->patch(route('admin.events.update', $this->event), [])->assertRedirect(route('dashboard')); + }); + it('updates an event', function () { + actAsAdmin(); + $this->patch(route('admin.events.update', $this->event), ['name' => 'Renamed Test Event']); + $this->assertDatabaseHas('events', [ + 'name' => 'Renamed Test Event', + ]); + }); +}); + describe('EventController::Destroy', function () { it('denies access to a non-admin user', function () { $event = \App\Models\Event::factory()->create();