2024-05-15 00:31:24 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
|
|
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;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
class Mod extends Model
|
|
|
|
{
|
|
|
|
use HasFactory, SoftDeletes;
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
'user_id',
|
|
|
|
'name',
|
|
|
|
'slug',
|
|
|
|
'description',
|
|
|
|
'license_id',
|
|
|
|
'source_code_link',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function user(): BelongsTo
|
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function license(): BelongsTo
|
|
|
|
{
|
|
|
|
return $this->belongsTo(License::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function versions(): HasMany
|
|
|
|
{
|
|
|
|
return $this->hasMany(ModVersion::class);
|
|
|
|
}
|
|
|
|
|
2024-05-17 17:11:54 -04:00
|
|
|
public function versionWithHighestSptVersion()
|
|
|
|
{
|
|
|
|
return $this->hasOne(ModVersion::class)->highestSptVersion();
|
|
|
|
}
|
|
|
|
|
2024-05-15 00:31:24 -04:00
|
|
|
protected function slug(): Attribute
|
|
|
|
{
|
|
|
|
return Attribute::make(
|
|
|
|
get: fn (string $value) => strtolower($value),
|
|
|
|
set: fn (string $value) => Str::slug($value),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|