categories = $categories; $this->posts = $posts; } public function create(BlogCategoryForm $form): BlogCategory { $category = BlogCategory::create( $form, $form->slug, $form->sort ); $this->categories->save($category); return $category; } public function edit($id, BlogCategoryForm $form): void { $category = $this->categories->get($id); $category->edit( $form, $form->slug, $form->sort ); $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); } }