Events - Tickets 🎟️
Tickets are Event App Products that enable participants and spectators to register or attend events. Each ticket is tied to a specific event, enforces sale windows, and can cap inventory. The Tickets subsystem handles creation, editing, ordering, and public display of these products.
Data Model
The Ticket model encapsulates all ticket-related data and relationships.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
class Ticket extends Model
{
use HasFactory;
protected $fillable = [
'title',
'description',
'event_id',
'amount',
'quantity_sold',
'max_quantity_sold',
'start_sale_date',
'end_sale_date',
'attendance_max',
'type',
'pre_purchase',
];
/** The event associated with the ticket. */
public function event(): HasOne
{
return $this->hasOne(\App\Models\Event::class, 'id', 'event_id');
}
}
- Fields
title,description: Display metadataamount: Price in dollarsstart_sale_date,end_sale_date: Sale windowtype:attendee,spectator, orteampre_purchase: Boolean flag for early access- Relationship
ticket->event()defines a one-to-one to Event
classDiagram
class Ticket {
+int id
+string title
+string description
+int event_id
+float amount
+DateTime start_sale_date
+DateTime end_sale_date
+enum type
+bool pre_purchase
+event()
}
class Event {
+int id
+string title
+tickets()
}
Ticket --> Event : belongsTo
Controller
The TicketController manages CRUD operations via AJAX and returns Blade modals.
| Method | Route Action | Description |
|---|---|---|
create |
GET /tickets/create?event_id | Returns “New Ticket” modal view |
store |
POST /tickets | Validates & creates a ticket, then redirects |
edit |
GET /tickets/{ticket}/edit | Returns “Edit Ticket” modal view |
update |
PUT /tickets/{ticket} | Validates & updates, then redirects |
destroy |
DELETE /tickets/{ticket} | Deletes the ticket and reloads page |
public function store(Request $request): JsonResponse
{
$request->validate([
'title' => 'required',
'start_sale_date' => 'required',
'end_sale_date' => 'required',
'amount' => 'required',
'type' => 'required',
'pre_purchase' => 'required',
]);
$ticket = Ticket::create($request->all());
$ticket->update(['event_id' => Event::find($request->get('event_id'))->id]);
return response()->json(['redirect' => route('event.tickets', $ticket->event)]);
}
All methods and validation rules are defined in app/Http/Controllers/TicketController.php .
Routes
Tickets are protected under Admin|Event Manager middleware and expose both resource and event-scoped routes:
Route::middleware('role:Admin|Event Manager')->group(function () {
Route::resources([
'tickets' => TicketController::class,
]);
// View tickets for a specific event
Route::get('/events/{event_id}/tickets', [EventController::class, 'indexEventTickets'])
->name('event.tickets');
});
- Resource Routes cover standard CRUD endpoints
- Event-Scoped view lists all tickets attached to an event
Dashboard Views
Tickets List
Located at resources/views/dashboard/events/partials/tickets.blade.php, this partial:
- Displays existing tickets in a sortable table
- Provides Sync Tickets and Save Order actions
- Loads Edit and Delete modals via AJAX
<x-block title="Tickets">
<x-slot name="action">
<form method="POST" action="{{ route('products.syncTickets', $event) }}" class="ajax-form">
<button class="btn btn-primary">Sync Tickets</button>
</form>
</x-slot>
<x-table bordered :sortable="true">
<x-slot name="headers">
<th></th><th>Name</th><th>Type</th><th>Amount</th><th>Start</th><th>End</th><th>Actions</th>
</x-slot>
<x-slot name="rows">
@foreach ($event->tickets as $i => $ticket)
<tr data-id="{{ $i }}">
<td><button class="handle"><i class="fas fa-bars"></i></button></td>
<td>{{ $ticket->name }}</td>
<td>{{ ucwords($ticket->type) }}</td>
<td>{{ money($ticket->amount) }}</td>
<td>{{ \Carbon\Carbon::parse($ticket->start_sale_date)->format('m-d-Y g:iA') }}</td>
<td>{{ \Carbon\Carbon::parse($ticket->end_sale_date)->format('m-d-Y g:iA') }}</td>
<td>
<button class="load-modal" data-href="{{ route('products.editTicket', $ticket) }}">Edit</button>
</td>
</tr>
@endforeach
</x-slot>
</x-table>
</x-block>
View source in dashboard/events/partials/tickets.blade.php .
Public Registration
Public pages use ticket data to render registration blocks:
- register-switch.blade.php shows ticket options and spectator blocks
- Enforces sale window (
start_sale_date/end_sale_date) - Supports upsell bundles via cloned ticket objects
The UI leverages Blade logic, Alpine.js, and Bootstrap grids to present each ticket as a selectable card.
Checkout Integration
Pre-sale and checkout flows interact with tickets via:
PresaleController::loadEventTeams()&loadTeamTickets()for dynamic forms- Livewire Checkout component reading
$event->tickets()->available() - Stripe-powered endpoints ensuring ticket availability and capacity rules
These integrations respect ticket limits and expiry rules defined on the Ticket model.
{
"title": "Tip",
"content": "Use pre_purchase flag to grant early access to select audiences."
}