$rule_groups * @property bool $is_smart * @property string $name * @property user $user * * @method static Builder orderBy(string $field, string $order = 'asc') */ class Playlist extends Model { use Searchable; use HasFactory; protected $hidden = ['user_id', 'created_at', 'updated_at']; protected $guarded = ['id']; protected $casts = [ 'user_id' => 'int', 'rules' => SmartPlaylistRulesCast::class, ]; protected $appends = ['is_smart']; public function songs(): BelongsToMany { return $this->belongsToMany(Song::class); } public function user(): BelongsTo { return $this->belongsTo(User::class); } public function getIsSmartAttribute(): bool { return $this->rule_groups->isNotEmpty(); } /** @return Collection|array */ public function getRuleGroupsAttribute(): Collection { return $this->rules; } /** @return array */ public function toSearchableArray(): array { return [ 'id' => $this->id, 'name' => $this->name, ]; } }