87 lines
1.8 KiB
PHP
87 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\HasTranslations;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class MusicProduction extends Model
|
|
{
|
|
use HasFactory, SoftDeletes, HasTranslations;
|
|
|
|
protected $table = 'music_productions';
|
|
|
|
protected $fillable = [
|
|
'title',
|
|
'slug',
|
|
'spotify_album_id',
|
|
'spotify_url',
|
|
'spotify_cover_url',
|
|
'spotify_type',
|
|
'spotify_synced_at',
|
|
'cover_image',
|
|
'content',
|
|
'client_name',
|
|
'production_date',
|
|
'gallery',
|
|
'is_active',
|
|
'sort_order',
|
|
];
|
|
|
|
/**
|
|
* Translatable fields
|
|
*/
|
|
protected $translatable = [
|
|
'title',
|
|
'content',
|
|
'client_name',
|
|
];
|
|
|
|
protected $casts = [
|
|
'production_date' => 'date',
|
|
'spotify_synced_at' => 'datetime',
|
|
'gallery' => 'array',
|
|
'is_active' => 'boolean',
|
|
'sort_order' => 'integer',
|
|
];
|
|
|
|
public function getUrlAttribute()
|
|
{
|
|
return route('music-productions.show', $this->slug);
|
|
}
|
|
|
|
public function getCoverImageUrlAttribute()
|
|
{
|
|
if ($this->cover_image) {
|
|
return asset('storage/' . $this->cover_image);
|
|
}
|
|
|
|
if ($this->spotify_cover_url) {
|
|
return $this->spotify_cover_url;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function getDisplayCoverImageAttribute(): ?string
|
|
{
|
|
if ($this->cover_image) {
|
|
return $this->cover_image;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function scopeActive($query)
|
|
{
|
|
return $query->where('is_active', true);
|
|
}
|
|
|
|
public function scopeOrdered($query)
|
|
{
|
|
return $query->orderBy('sort_order', 'asc')->orderBy('production_date', 'desc');
|
|
}
|
|
}
|