mirror of
https://github.com/sp-tarkov/forge.git
synced 2025-02-13 04:30:41 -05:00
- Updated the SptVersion and ModVersion dependancies to resolve *all* compatible versions and introduced new relationships to pull just the latest compatible version. Had to rewrite a *bunch*, but it should be much more capable now. It can be expensive to resolve these properties when iterated over, so *make sure they're eager loaded using the `with` method when you're building the queries*. - Updated the mod listing Livewire component to save the filter options within the PHP session instead of in browser local storage. *Much* cleaner. - Removed caching from homepage queries to see how they preform on production. Will add back later. - Updated ModVersion factory to create SptVersions if there are none specified. - Probably lots of other changes too... I need to make smaller commits. :(
93 lines
2.9 KiB
PHP
93 lines
2.9 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\BelongsToMany;
|
|
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(): HasMany
|
|
{
|
|
return $this->hasMany(ModDependency::class);
|
|
}
|
|
|
|
/**
|
|
* The relationship between a mod version and its resolved dependencies.
|
|
*/
|
|
public function resolvedDependencies(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(ModVersion::class, 'mod_resolved_dependencies', 'mod_version_id', 'resolved_mod_version_id')
|
|
->withPivot('dependency_id')
|
|
->withTimestamps();
|
|
}
|
|
|
|
/**
|
|
* The relationship between a mod version and its each of it's resolved dependencies' latest versions.
|
|
*/
|
|
public function latestResolvedDependencies(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(ModVersion::class, 'mod_resolved_dependencies', 'mod_version_id', 'resolved_mod_version_id')
|
|
->withPivot('dependency_id')
|
|
->join('mod_versions as latest_versions', function ($join) {
|
|
$join->on('latest_versions.id', '=', 'mod_versions.id')
|
|
->whereRaw('latest_versions.version = (SELECT MAX(mv.version) FROM mod_versions mv WHERE mv.mod_id = mod_versions.mod_id)');
|
|
})
|
|
->with('mod:id,name,slug')
|
|
->withTimestamps();
|
|
}
|
|
|
|
/**
|
|
* The relationship between a mod version and each of its SPT versions' latest version.
|
|
* Hint: Be sure to call `->first()` on this to get the actual instance.
|
|
*/
|
|
public function latestSptVersion(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(SptVersion::class, 'mod_version_spt_version')
|
|
->orderBy('version', 'desc')
|
|
->limit(1);
|
|
}
|
|
|
|
/**
|
|
* The relationship between a mod version and its SPT versions.
|
|
*/
|
|
public function sptVersions(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(SptVersion::class, 'mod_version_spt_version')
|
|
->orderByDesc('version');
|
|
}
|
|
}
|