public function doesSlugExist($slug, $bookId, $currentId = false) { $query = $this->chapter->where('slug', '=', $slug)->where('book_id', '=', $bookId); if ($currentId) { $query = $query->where('id', '!=', $currentId); } return $query->count() > 0; }