public function add($author) { if (is_string($author)) { $author = Author::firstOrCreate(['name' => $author]); } debug('No books for this author'); $authorData = $this->authorSearchService->find($author->name, true); if ($authorData->isEmpty()) { throw new AuthorNotFoundException("Unable to find {$author}"); } $authorData = $authorData->first(); $googleBookIds = $this->getGoogleBookIds($authorData); $existingBooks = Book::whereIn('google_books_id', $googleBookIds)->get(); $this->createMissingBooks($author, $authorData, $existingBooks); return $author; }