categories = $categories; $this->posts = $posts; } public function create(BlogCategoryForm $form): BlogCategory { $category = BlogCategory::create( $form->name, $form->slug, $form->title, $form->description, $form->sort, new Meta( $form->meta->title, $form->meta->description, $form->meta->keywords ) ); $this->categories->save($category); return $category; } public function edit($id, BlogCategoryForm $form): void { $category = $this->categories->get($id); $category->edit( $form->name, $form->slug, $form->title, $form->description, $form->sort, new Meta( $form->meta->title, $form->meta->description, $form->meta->keywords ) ); $this->categories->save($category); } public function remove($id): void { $category = $this->categories->get($id); if ($this->posts->existsByCategory($category->id)) { throw new \DomainException('Unable to remove category with posts.'); } $this->categories->remove($category); } }