mirror of
https://github.com/pacnpal/thrillwiki_laravel.git
synced 2025-12-20 14:11:10 -05:00
141 lines
3.4 KiB
Markdown
141 lines
3.4 KiB
Markdown
# Ride System Models Documentation
|
|
|
|
## Overview
|
|
The rides system is implemented through a set of interconnected Eloquent models that handle different aspects of ride management. The implementation maintains feature parity with the Django original while leveraging Laravel's conventions and features.
|
|
|
|
## Model Structure
|
|
|
|
### RideModel
|
|
- **Purpose**: Templates for specific ride types/products
|
|
- **Key Features**:
|
|
- Manufacturer relationship
|
|
- Category type from RideCategory enum
|
|
- Has many Rides
|
|
- Full name accessor for manufacturer + model name
|
|
- **File**: `app/Models/RideModel.php`
|
|
|
|
### Ride
|
|
- **Purpose**: Individual ride installations at parks
|
|
- **Key Features**:
|
|
- Complex relationships to:
|
|
- Park (required)
|
|
- ParkArea (optional)
|
|
- Manufacturer (optional)
|
|
- Designer (optional)
|
|
- RideModel (optional)
|
|
- RollerCoasterStats (optional one-to-one)
|
|
- Status tracking with dates
|
|
- Automatic slug generation
|
|
- Type safety through enums
|
|
- **File**: `app/Models/Ride.php`
|
|
|
|
### RollerCoasterStats
|
|
- **Purpose**: Extended statistics for roller coaster type rides
|
|
- **Key Features**:
|
|
- One-to-one relationship with Ride
|
|
- Physical measurements with decimal precision
|
|
- Track material and type enums
|
|
- Train configuration tracking
|
|
- Total seats calculation
|
|
- **File**: `app/Models/RollerCoasterStats.php`
|
|
|
|
### Designer
|
|
- **Purpose**: Track ride designers and their work
|
|
- **Key Features**:
|
|
- Basic information storage
|
|
- Automatic slug generation
|
|
- Has many relationship to rides
|
|
- **File**: `app/Models/Designer.php`
|
|
|
|
## Key Design Decisions
|
|
|
|
### 1. Type Safety
|
|
- Used PHP 8.1 enums for all constrained choices:
|
|
- RideCategory
|
|
- RideStatus
|
|
- TrackMaterial
|
|
- RollerCoasterType
|
|
- LaunchType
|
|
|
|
### 2. Data Integrity
|
|
- Proper foreign key constraints
|
|
- Appropriate nullOnDelete vs cascadeOnDelete choices
|
|
- Unique constraints where needed
|
|
|
|
### 3. Automatic Features
|
|
- Slug generation on model creation
|
|
- Proper cast declarations for:
|
|
- Dates
|
|
- Decimals
|
|
- Enums
|
|
- Integers
|
|
|
|
### 4. Optimization Choices
|
|
- No timestamps on RollerCoasterStats (reduces overhead)
|
|
- Appropriate indexes on foreign keys
|
|
- Efficient relationships setup
|
|
|
|
### 5. Laravel Conventions
|
|
- Followed naming conventions
|
|
- Used protected properties for configurations
|
|
- Proper method return type declarations
|
|
- Relationship method naming
|
|
|
|
## Usage Examples
|
|
|
|
### Creating a New Ride
|
|
```php
|
|
$ride = Ride::create([
|
|
'name' => 'Thunderbolt',
|
|
'park_id' => $park->id,
|
|
'category' => RideCategory::ROLLER_COASTER,
|
|
'status' => RideStatus::OPERATING,
|
|
]);
|
|
```
|
|
|
|
### Adding Roller Coaster Stats
|
|
```php
|
|
$ride->coasterStats()->create([
|
|
'height_ft' => 120.5,
|
|
'track_material' => TrackMaterial::STEEL,
|
|
'roller_coaster_type' => RollerCoasterType::SITDOWN,
|
|
]);
|
|
```
|
|
|
|
### Getting Ride with All Relations
|
|
```php
|
|
$ride = Ride::with([
|
|
'park',
|
|
'parkArea',
|
|
'manufacturer',
|
|
'designer',
|
|
'rideModel',
|
|
'coasterStats',
|
|
])->find($id);
|
|
```
|
|
|
|
## Relationship Maps
|
|
|
|
### RideModel
|
|
- ← belongs to → Manufacturer
|
|
- ← has many → Ride
|
|
|
|
### Ride
|
|
- ← belongs to → Park
|
|
- ← belongs to → ParkArea
|
|
- ← belongs to → Manufacturer
|
|
- ← belongs to → Designer
|
|
- ← belongs to → RideModel
|
|
- ← has one → RollerCoasterStats
|
|
|
|
### RollerCoasterStats
|
|
- ← belongs to → Ride
|
|
|
|
### Designer
|
|
- ← has many → Ride
|
|
|
|
## Future Enhancements
|
|
1. Add review relationships
|
|
2. Implement photo relationships
|
|
3. Add history tracking
|
|
4. Consider adding composite indexes for common queries |