forge/app/Models/ModDependency.php

75 lines
1.9 KiB
PHP
Raw Permalink Normal View History

<?php
2025-01-30 00:23:55 -05:00
declare(strict_types=1);
namespace App\Models;
2025-01-30 15:44:05 -05:00
use Carbon\Carbon;
2025-01-30 20:49:56 -05:00
use Database\Factories\ModDependencyFactory;
2025-01-30 15:44:05 -05:00
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
2025-01-30 15:44:05 -05:00
/**
* ModDependency Model
*
* @property int $id
* @property int $mod_version_id
* @property int $dependent_mod_id
* @property string $constraint
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property-read ModVersion $modVersion
* @property-read Mod $dependentMod
* @property-read Collection<int, ModResolvedDependency> $resolvedDependencies
*/
class ModDependency extends Model
{
2025-01-30 20:49:56 -05:00
/** @use HasFactory<ModDependencyFactory> */
use HasFactory;
/**
* The relationship between the mod dependency and the mod version.
2024-09-12 13:19:52 -04:00
*
2025-01-30 15:44:05 -05:00
* @return BelongsTo<ModVersion, $this>
*/
public function modVersion(): BelongsTo
{
return $this->belongsTo(ModVersion::class);
}
/**
* The relationship between the mod dependency and the resolved dependency.
2024-09-12 13:19:52 -04:00
*
2025-01-30 15:44:05 -05:00
* @return HasMany<ModResolvedDependency, $this>
*/
public function resolvedDependencies(): HasMany
{
return $this->hasMany(ModResolvedDependency::class, 'dependency_id')
->chaperone();
}
/**
* The relationship between the mod dependency and the dependent mod.
2024-09-12 13:19:52 -04:00
*
2025-01-30 15:44:05 -05:00
* @return BelongsTo<Mod, $this>
*/
public function dependentMod(): BelongsTo
{
return $this->belongsTo(Mod::class, 'dependent_mod_id');
}
2024-10-12 13:18:04 -06:00
/**
* The attributes that should be cast to native types.
*/
protected function casts(): array
{
return [
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
}
}