Files
back-meditation/app/Models/Scene.php
T
2026-06-16 17:15:08 +03:30

46 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Scene extends Model
{
protected $fillable = ['theme_id', 'name', 'image_path', 'video_path', 'sound_path', 'order', 'is_active', 'is_premium'];
protected $casts = [
'is_active' => 'boolean',
'is_premium' => 'boolean',
'order' => 'integer',
];
public function theme(): BelongsTo
{
return $this->belongsTo(Theme::class);
}
protected $appends = ['image_url', 'video_url', 'sound_url', 'has_video'];
public function getImageUrlAttribute(): ?string
{
return $this->image_path ? asset('storage/' . $this->image_path) : null;
}
public function getVideoUrlAttribute(): ?string
{
return $this->video_path ? asset('storage/' . $this->video_path) : null;
}
public function getSoundUrlAttribute(): ?string
{
return $this->sound_path ? asset('storage/' . $this->sound_path) : null;
}
// Whether this scene can be shown as a video (the "تبدیل صحنه به ویدیو" toggle).
public function getHasVideoAttribute(): bool
{
return !empty($this->video_path);
}
}