95 lines
2.2 KiB
PHP
95 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class Entry extends Model
|
|
{
|
|
|
|
/**
|
|
* @var string[]
|
|
*/
|
|
protected $fillable = [
|
|
'type',
|
|
'title',
|
|
'slug',
|
|
'description',
|
|
'main_image',
|
|
'state',
|
|
'featured',
|
|
'game_id',
|
|
'platform_id',
|
|
'status_id',
|
|
'version',
|
|
'release_date',
|
|
'staff_credits',
|
|
'relevant_link',
|
|
'youtube_link',
|
|
'user_id',
|
|
'complete_title',
|
|
'comments_thread_id',
|
|
];
|
|
|
|
/**
|
|
* @var string[]
|
|
*/
|
|
protected $casts = [
|
|
'featured' => 'boolean',
|
|
'release_date' => 'date',
|
|
];
|
|
|
|
public function scopePublished( Builder $query ): Builder {
|
|
return $query->where( 'state', 'published' );
|
|
}
|
|
|
|
/**
|
|
* Return game link.
|
|
* @return BelongsTo
|
|
*/
|
|
public function game(): BelongsTo {
|
|
return $this->belongsTo(Game::class);
|
|
}
|
|
|
|
public function platform(): BelongsTo {
|
|
return $this->belongsTo(Platform::class);
|
|
}
|
|
|
|
public function getRealPlatform(): ?Platform {
|
|
return $this->game?->platform ?? $this->platform;
|
|
}
|
|
|
|
public function status(): BelongsTo {
|
|
return $this->belongsTo(Status::class );
|
|
}
|
|
|
|
public function authors(): BelongsToMany {
|
|
return $this->belongsToMany(Author::class, 'entry_authors');
|
|
}
|
|
|
|
public function languages(): BelongsToMany {
|
|
return $this->belongsToMany(Language::class, 'entry_languages');
|
|
}
|
|
|
|
public function modifications(): BelongsToMany {
|
|
return $this->belongsToMany( Modification::class, 'entry_modifications');
|
|
}
|
|
|
|
public function files(): HasMany {
|
|
return $this->hasMany(EntryFile::class)->orderBy('filename');
|
|
}
|
|
|
|
public function gallery(): HasMany {
|
|
return $this->hasMany(EntryGallery::class)->orderBy('id');
|
|
}
|
|
|
|
public function hashes(): HasMany {
|
|
return $this->hasMany(EntryHash::class);
|
|
}
|
|
|
|
}
|