self::create($jsonArray)); } public static function create(array $jsonArray): self { $rules = collect(array_map(static function (array $rawRuleConfig) { return SmartPlaylistRule::create($rawRuleConfig); }, $jsonArray['rules'])); return new self(Arr::get($jsonArray, 'id'), $rules); } /** @return array */ public function toArray(): array { return [ 'id' => $this->id, 'rules' => $this->rules->toArray(), ]; } }