mirror of
https://github.com/sp-tarkov/forge.git
synced 2025-02-13 04:30:41 -05:00
This update gives mod versions a supported SPT version field that accepts a semantic version. The latest supported SPT version will be automatically resolved based on the semvar. Next up: I need to update the ModVersion to SptVersion relationship to be a many-to-many and expand the resolution to resolve multiple versions.
61 lines
1.4 KiB
PHP
61 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Scopes\DisabledScope;
|
|
use App\Models\Scopes\PublishedScope;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property int $mod_id
|
|
* @property string $version
|
|
*/
|
|
class ModVersion extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
/**
|
|
* Post boot method to configure the model.
|
|
*/
|
|
protected static function booted(): void
|
|
{
|
|
static::addGlobalScope(new DisabledScope);
|
|
static::addGlobalScope(new PublishedScope);
|
|
}
|
|
|
|
/**
|
|
* The relationship between a mod version and mod.
|
|
*/
|
|
public function mod(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Mod::class);
|
|
}
|
|
|
|
/**
|
|
* The relationship between a mod version and its dependencies.
|
|
*/
|
|
public function dependencies(bool $resolvedOnly = true): HasMany
|
|
{
|
|
$relation = $this->hasMany(ModDependency::class);
|
|
|
|
if ($resolvedOnly) {
|
|
$relation->whereNotNull('resolved_version_id');
|
|
}
|
|
|
|
return $relation;
|
|
}
|
|
|
|
/**
|
|
* The relationship between a mod version and SPT version.
|
|
*/
|
|
public function sptVersion(): BelongsTo
|
|
{
|
|
return $this->belongsTo(SptVersion::class, 'resolved_spt_version_id');
|
|
}
|
|
}
|