|RadioAutoDjTrack where($column, $operator = null, $value = null) * @method static \Illuminate\Database\Eloquent\Builder|RadioAutoDjTrack create($attributes = []) * @method static \Illuminate\Database\Eloquent\Builder|RadioAutoDjTrack active() * @method static \Illuminate\Database\Eloquent\Builder|RadioAutoDjTrack orderBy($column, $direction = 'asc') * * @property string $title * @property string|null $artist * @property string|null $album * @property string|null $artwork_url * @property int|null $duration * @property int $play_count * @property \Carbon\Carbon|null $last_played_at * @property bool $is_active * @property int $sort_order */ class RadioAutoDjTrack extends Model { #[\Override] protected $table = 'radio_auto_dj_playlist'; #[\Override] protected $guarded = ['id', 'created_at', 'updated_at']; #[\Override] protected $casts = [ 'duration' => 'integer', 'play_count' => 'integer', 'last_played_at' => 'datetime', 'is_active' => 'boolean', 'sort_order' => 'integer', ]; public function scopeActive($query) { return $query->where('is_active', true); } public function scopeOrdered($query) { return $query->orderBy('sort_order')->orderBy('title'); } public function markPlayed(): void { $this->increment('play_count'); $this->update(['last_played_at' => now()]); } public static function getNextTrack(): ?self { $last = self::active()->orderBy('last_played_at', 'asc')->orderBy('sort_order')->first(); if ($last) { return $last; } return self::active()->ordered()->first(); } }