You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`
public function upload(Request $request)
{
$request->validate([
'epub_file' => 'required|mimes:epub'
]);
$filename = 'eb_' . uniqid() . '.epub';
$path = $request->file('epub_file')->storeAs('epubs', $filename);
$ebook = Ebook::read(storage_path('app/' . $path));
// Access metadata and properties of the eBook
$title = $ebook->getTitle();
$author = $ebook->getAuthorMain();
$description = $ebook->getDescription() ?? 'No Description added';
$coverImage = $ebook->getCover();
// Store cover image
$coverPath = null;
if ($coverImage) {
$coverFilename = 'cover_' . uniqid() . '.png'; // Assuming cover image format is PNG
$coverContents = $coverImage->getContents();
$fullPath = 'covers/' . $coverFilename;
Storage::put($fullPath, $coverContents);
$coverPath = $fullPath; // Store the full path including 'storage/app'
}
// Create a new book
$book = Book::create([
'name' => $title,
'author' => $author,
'isbn' => null,
'book_cover' => $coverPath,
'description' => $description
]);
// Get chapters from the EPUB
$epub = $ebook->getParser()?->getEpub();
$chapters = $epub->getChapters(); // Ensure this line is correctly retrieving chapters
dd($chapters); // Debug to check if chapters are now correctly retrieved
// Save chapters to database
foreach ($chapters as $index => $chapter) {
Chapter::create([
'title' => $chapter->label(), // Use label() method to get the chapter label
'content' => $chapter->content(), // Use content() method to get the chapter content
'book_id' => $book->id,
'src' => $chapter->source(), // Use source() method to get the chapter source
]);
}
return redirect()->route('books.index')->with('success', 'Book uploaded successfully. File name: ' . $filename);
}
`
What happened?
Upon attempting to upload an EPUB file through the upload function, the process completes successfully without any errors reported. However, upon inspection, it's found that no chapters are created in the database despite the EPUB containing multiple chapters.
How to reproduce the bug
Expected Behavior:
After the file is uploaded, the function should extract chapters from the EPUB file and save them to the database. These chapters should be retrievable and displayed for the user.
Actual Behavior:
After uploading an EPUB file, the function successfully creates a book entry in the database with the correct title, author, cover image, and description. However, no chapters are created or saved in the database, even though the EPUB contains multiple chapters.
Debugging Steps Undertaken:
Checked the $chapters variable after retrieving it from the EPUB file. Used dd($chapters) to ensure that chapters are correctly retrieved. However, the dump shows an empty array, indicating that no chapters are being extracted.
Verified that the EPUB file contains multiple chapters by manually inspecting the file using EPUB reader software.
Package Version
2.3.8
PHP Version
8.2
Which operating systems does with happen with?
Windows
Notes
No response
The text was updated successfully, but these errors were encountered:
`
public function upload(Request $request)
{
$request->validate([
'epub_file' => 'required|mimes:epub'
]);
`
What happened?
Upon attempting to upload an EPUB file through the upload function, the process completes successfully without any errors reported. However, upon inspection, it's found that no chapters are created in the database despite the EPUB containing multiple chapters.
How to reproduce the bug
Expected Behavior:
After the file is uploaded, the function should extract chapters from the EPUB file and save them to the database. These chapters should be retrievable and displayed for the user.
Actual Behavior:
After uploading an EPUB file, the function successfully creates a book entry in the database with the correct title, author, cover image, and description. However, no chapters are created or saved in the database, even though the EPUB contains multiple chapters.
Debugging Steps Undertaken:
Checked the $chapters variable after retrieving it from the EPUB file. Used dd($chapters) to ensure that chapters are correctly retrieved. However, the dump shows an empty array, indicating that no chapters are being extracted.
Verified that the EPUB file contains multiple chapters by manually inspecting the file using EPUB reader software.
Package Version
2.3.8
PHP Version
8.2
Which operating systems does with happen with?
Windows
Notes
No response
The text was updated successfully, but these errors were encountered: