AIM Church Website
A church website backend that treats registration capacity and cancellation as data integrity concerns.

The backend supports everyday publishing tasks for AIM Church Busan, including events, sermons, and announcements. The event flow needed particular care because the number of visible spots could change between loading a page and submitting a registration.
Keeping the last seat consistent
Laravel checks for an existing registration first, then uses a database transaction for the capacity update and registration write. For a limited-capacity event, the decrement includes a condition that spots must remain. If the write fails, the transaction can roll back the seat decrement. A unique constraint handles two requests that both pass the first duplicate check.
return DB::transaction(function () use ($event, $planningCenterUserId, $existing) {
if (!is_null($event->remaining_spots)) {
$updated = Event::where('id', $event->id)
->where('remaining_spots', '>', 0)
->decrement('remaining_spots');
if (!$updated) {
throw ValidationException::withMessages([
'event_id' => 'This event is fully booked.',
]);
}
}
if ($existing?->isCancelled()) {
$existing->update(['status' => EventRegistration::STATUS_REGISTERED]);
return $existing->fresh();
}
try {
return EventRegistration::create([
'event_id' => $event->id,
'planning_center_user_id' => $planningCenterUserId,
'status' => EventRegistration::STATUS_REGISTERED,
]);
} catch (QueryException $e) {
// Unique constraint violation (event_id, planning_center_user_id)
// — happens if two requests race past the initial check above.
if ($this->isUniqueViolation($e)) {
throw ValidationException::withMessages([
'event_id' => 'You have already registered for this event.',
]);
}
throw $e;
}
});Returning capacity on cancellation
The cancellation path locks the registration row before marking it cancelled. It also restores a seat for limited-capacity events in the same transaction. Repeating a cancellation is rejected before it can increment the number of available spots again.
public function cancel(Event $event, int $planningCenterUserId): void
{
DB::transaction(function () use ($event, $planningCenterUserId) {
$registration = EventRegistration::where('event_id', $event->id)
->where('planning_center_user_id', $planningCenterUserId)
->lockForUpdate()
->firstOrFail();
if ($registration->isCancelled()) {
throw ValidationException::withMessages([
'event_id' => 'This registration is already cancelled.',
]);
}
$registration->update(['status' => EventRegistration::STATUS_CANCELLED]);
if (!is_null($event->remaining_spots)) {
$event->increment('remaining_spots');
}
});
}What I learned
The availability shown in a page is a snapshot. The write path needs to enforce the same rule at the moment a registration is created or cancelled.
Related article
Wiring Up Planning Center OAuth in Laravel: the Session Based Way