*/ protected $fillable = [ 'name', 'slug', 'website', 'headquarters', 'description', 'total_rides', 'total_roller_coasters', 'is_active', 'industry_presence_score', 'market_share_percentage', 'founded_year', 'specialization', 'product_portfolio', 'manufacturing_categories', 'global_installations', 'primary_market', 'is_major_manufacturer', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'total_rides' => 'integer', 'total_roller_coasters' => 'integer', 'is_active' => 'boolean', 'industry_presence_score' => 'integer', 'market_share_percentage' => 'decimal:2', 'founded_year' => 'integer', 'manufacturing_categories' => 'array', 'global_installations' => 'integer', 'is_major_manufacturer' => 'boolean', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'datetime', ]; /** * Get the rides manufactured by this company. */ public function rides(): HasMany { return $this->hasMany(Ride::class, 'manufacturer_id'); } /** * Update ride statistics. */ public function updateStatistics(): void { $this->total_rides = $this->rides()->count(); $this->total_roller_coasters = $this->rides() ->where('category', 'RC') ->count(); $this->save(); } /** * Get the manufacturer's name with total rides. */ public function getDisplayNameAttribute(): string { return "{$this->name} ({$this->total_rides} rides)"; } /** * Get formatted website URL (ensures proper URL format). */ public function getWebsiteUrlAttribute(): string { if (!$this->website) { return ''; } $website = $this->website; if (!str_starts_with($website, 'http://') && !str_starts_with($website, 'https://')) { $website = 'https://' . $website; } return $website; } /** * Scope a query to only include major manufacturers (with multiple rides). */ public function scopeMajorManufacturers($query, int $minRides = 5) { return $query->where('total_rides', '>=', $minRides); } /** * Scope a query to only include coaster manufacturers. */ public function scopeCoasterManufacturers($query) { return $query->where('total_roller_coasters', '>', 0); } /** * Scope a query to only include active manufacturers. */ public function scopeActive($query) { return $query->where('is_active', true); } /** * Scope a query for optimized loading with statistics. */ public function scopeOptimized($query) { return $query->select(['id', 'name', 'slug', 'total_rides', 'total_roller_coasters', 'is_active']); } /** * Get the route key for the model. */ public function getRouteKeyName(): string { return 'slug'; } }