parent
1acb286ac8
commit
4548be098a
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
<x-modal-body show-var="{{$currentRenameModalName}}">
|
||||
<x-slot:title>
|
||||
Rename Event
|
||||
</x-slot:title>
|
||||
<x-form.form id="update-bonus-score-form" action="{{ route('admin.events.update', $event) }}" method="PATCH">
|
||||
<x-form.body-grid columns="12">
|
||||
<x-form.field name="name" label_text="Name" colspan="8" value="{{ $event->name }}" />
|
||||
<div class="col-start-9 col-span-4 row-start-2">
|
||||
<x-form.button >Update Event</x-form.button>
|
||||
</div>
|
||||
|
||||
</x-form.body-grid>
|
||||
</x-form.form>
|
||||
</x-modal-body>
|
||||
|
|
@ -8,36 +8,50 @@
|
|||
</x-slot:right_side>
|
||||
</x-card.heading>
|
||||
|
||||
<x-table.table>
|
||||
<x-table.body>
|
||||
@foreach($events as $event)
|
||||
<tr>
|
||||
<x-table.td>{{ $event->name }}, {{ $event->auditions()->count() }} Auditions</x-table.td>
|
||||
<x-table.td class="text-right">
|
||||
|
||||
@if($event->auditions()->count() == 0)
|
||||
<form method="POST" action="{{ route('admin.events.destroy', ['event' => $event->id]) }}">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="text-red-600 text-right">Delete Event</button>
|
||||
</form>
|
||||
@endif
|
||||
<div x-data="{ {{ $renameModalXdata}} }">
|
||||
@foreach($events as $event)
|
||||
@php($currentRenameModalName = "showRenameModal_".$event->id)
|
||||
@include('admin.event.index-rename-event-modal')
|
||||
@endforeach
|
||||
|
||||
<x-table.table>
|
||||
<x-table.body>
|
||||
@foreach($events as $event)
|
||||
|
||||
<tr>
|
||||
|
||||
<x-table.td>{{ $event->name }}
|
||||
<button class="text-xs" @click="showRenameModal_{{$event->id}} = true">[rename]</button>
|
||||
<br/>
|
||||
<span class="text-xs">{{ $event->auditions()->count() }} Auditions</span>
|
||||
</x-table.td>
|
||||
<x-table.td class="text-right">
|
||||
|
||||
@if($event->auditions()->count() == 0)
|
||||
<form method="POST"
|
||||
action="{{ route('admin.events.destroy', ['event' => $event->id]) }}">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="text-red-600 text-right">Delete Event</button>
|
||||
</form>
|
||||
@endif
|
||||
</x-table.td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</x-table.body>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<x-form.form method="POST" :action="route('admin.events.store')" class="!px-0 !py-0">
|
||||
<x-table.td>
|
||||
<x-form.field name="name" label_text="Add New Event"/>
|
||||
</x-table.td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</x-table.body>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<x-form.form method="POST" :action="route('admin.events.store')" class="!px-0 !py-0">
|
||||
<x-table.td>
|
||||
<x-form.field name="name" label_text="Add New Event" />
|
||||
</x-table.td>
|
||||
<x-table.td>
|
||||
<x-form.button class="mt-6">Create</x-form.button>
|
||||
</x-table.td>
|
||||
</x-form.form>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</x-table.table>
|
||||
<x-table.td>
|
||||
<x-form.button class="mt-6">Create</x-form.button>
|
||||
</x-table.td>
|
||||
</x-form.form>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</x-table.table>
|
||||
</div>
|
||||
</x-card.card>
|
||||
</x-layout.app>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue