hasMany(SpecAttr::class, "spec_id", "id"); } public function format(...$options) { $return = [ "id" => $this->id, "name" => $this->name, "en_name" => $this->en_name, "is_custom" => (bool)$this->is_custom, "index_weight" => $this->index_weight, "category_weight" => $this->category_weight, "search_weight" => $this->search_weight, "created_at" => $this->created_at->format("Y-m-d"), ]; if (in_array(self::FORMAT_ATTR, $options)) { $return['attr'] = $this->attrs->map(function (SpecAttr $m) { return [ "id" => $m->id, "name" => $m->name, ]; }); } return $return; } }