Files
thrillwiki_laravel/app/Models/RideModel.php

58 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use App\Enums\RideCategory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class RideModel extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array<string>
*/
protected $fillable = [
'name',
'manufacturer_id',
'description',
'category',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'category' => RideCategory::class,
];
/**
* Get the manufacturer that produces this ride model.
*/
public function manufacturer(): BelongsTo
{
return $this->belongsTo(Manufacturer::class);
}
/**
* Get the rides that are instances of this model.
*/
public function rides(): HasMany
{
return $this->hasMany(Ride::class);
}
/**
* Get the full name of the ride model including manufacturer.
*/
public function getFullNameAttribute(): string
{
return $this->manufacturer
? "{$this->manufacturer->name} {$this->name}"
: $this->name;
}
}