Files
thrillwiki_laravel/app/Models/Manufacturer.php
pacnpal 97a7682eb7 Add Livewire components for parks, rides, and manufacturers
- Implemented ParksLocationSearch component with loading state and refresh functionality.
- Created ParksMapView component with similar structure and functionality.
- Added RegionalParksListing component for displaying regional parks.
- Developed RidesListingUniversal component for universal listing integration.
- Established ManufacturersListing view with navigation and Livewire integration.
- Added feature tests for various Livewire components including OperatorHierarchyView, OperatorParksListing, OperatorPortfolioCard, OperatorsListing, OperatorsRoleFilter, ParksListing, ParksLocationSearch, ParksMapView, and RegionalParksListing to ensure proper rendering and adherence to patterns.
2025-06-23 21:31:05 -04:00

144 lines
3.6 KiB
PHP

<?php
namespace App\Models;
use App\Traits\HasSlugHistory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
class Manufacturer extends Model
{
use HasFactory, HasSlugHistory, SoftDeletes;
/**
* The attributes that are mass assignable.
*
* @var array<string>
*/
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<string, string>
*/
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';
}
}