Files
thrillwiki_laravel/app/Models/RollerCoasterStats.php

79 lines
1.9 KiB
PHP

<?php
namespace App\Models;
use App\Enums\TrackMaterial;
use App\Enums\RollerCoasterType;
use App\Enums\LaunchType;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class RollerCoasterStats extends Model
{
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
/**
* The attributes that are mass assignable.
*
* @var array<string>
*/
protected $fillable = [
'ride_id',
'height_ft',
'length_ft',
'speed_mph',
'inversions',
'ride_time_seconds',
'track_type',
'track_material',
'roller_coaster_type',
'max_drop_height_ft',
'launch_type',
'train_style',
'trains_count',
'cars_per_train',
'seats_per_car',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'height_ft' => 'decimal:2',
'length_ft' => 'decimal:2',
'speed_mph' => 'decimal:2',
'max_drop_height_ft' => 'decimal:2',
'track_material' => TrackMaterial::class,
'roller_coaster_type' => RollerCoasterType::class,
'launch_type' => LaunchType::class,
'trains_count' => 'integer',
'cars_per_train' => 'integer',
'seats_per_car' => 'integer',
];
/**
* Get the ride that owns these statistics.
*/
public function ride(): BelongsTo
{
return $this->belongsTo(Ride::class);
}
/**
* Calculate total seating capacity.
*/
public function getTotalSeatsAttribute(): ?int
{
if ($this->trains_count && $this->cars_per_train && $this->seats_per_car) {
return $this->trains_count * $this->cars_per_train * $this->seats_per_car;
}
return null;
}
}