$songs * @property ?SmartPlaylistRuleGroupCollection $rule_groups * @property ?SmartPlaylistRuleGroupCollection $rules * @property Carbon $created_at * @property bool $own_songs_only */ class Playlist extends Model { use Searchable; use HasFactory; protected $hidden = ['user_id', 'created_at', 'updated_at']; protected $guarded = ['id']; protected $casts = [ 'rules' => SmartPlaylistRulesCast::class, 'own_songs_only' => 'bool', ]; protected $appends = ['is_smart']; public function songs(): BelongsToMany { return $this->belongsToMany(Song::class); } public function user(): BelongsTo { return $this->belongsTo(User::class); } public function folder(): BelongsTo { return $this->belongsTo(PlaylistFolder::class); } protected function isSmart(): Attribute { return Attribute::get(fn (): bool => (bool) $this->rule_groups?->isNotEmpty()); } protected function ruleGroups(): Attribute { // aliasing the attribute to avoid confusion return Attribute::get(fn () => $this->rules); } /** @return array */ public function toSearchableArray(): array { return [ 'id' => $this->id, 'name' => $this->name, ]; } }