Initial commit
This commit is contained in:
93
app/Models/Entry.php
Normal file
93
app/Models/Entry.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?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',
|
||||
];
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user