id); \Log::info('Request has file: ' . ($request->hasFile('file') ? 'YES' : 'NO')); if ($request->hasFile('file')) { $file = $request->file('file'); \Log::info('File original name: ' . $file->getClientOriginalName()); \Log::info('File size: ' . $file->getSize()); \Log::info('File mime type: ' . $file->getMimeType()); \Log::info('File is valid: ' . ($file->isValid() ? 'YES' : 'NO')); } $validated = $request->validate([ 'file' => 'required|file|mimes:pdf|max:512000', // 500MB max 'title' => 'required|string|max:255', 'summary' => 'nullable|string', ]); \Log::info('Validation passed'); // Get the uploaded file $file = $request->file('file'); // Generate unique filename $storedFilename = Str::uuid() . '.pdf'; \Log::info('Generated filename: ' . $storedFilename); // Store file in storage/app/public/documents \Log::info('Attempting to store file...'); $filePath = $file->storeAs('documents', $storedFilename, 'public'); \Log::info('File stored at: ' . $filePath); // Get the highest display order for this entry $maxOrder = $docketEntry->documents()->max('display_order') ?? -1; \Log::info('Max display order: ' . $maxOrder); // Create document record \Log::info('Creating document record...'); $document = Document::create([ 'docket_entry_id' => $docketEntry->id, 'title' => $validated['title'], 'original_filename' => $file->getClientOriginalName(), 'stored_filename' => $storedFilename, 'file_path' => $filePath, 'file_size' => $file->getSize(), 'mime_type' => $file->getMimeType(), 'summary' => $validated['summary'] ?? null, 'display_order' => $maxOrder + 1, ]); \Log::info('Document created with ID: ' . $document->id); \Log::info('=== PDF UPLOAD DEBUG END (SUCCESS) ==='); return redirect()->route('admin.docket-entries.show', $docketEntry->id) ->with('success', 'Document uploaded successfully.'); } catch (\Exception $e) { \Log::error('=== PDF UPLOAD ERROR ==='); \Log::error('Error message: ' . $e->getMessage()); \Log::error('Error file: ' . $e->getFile()); \Log::error('Error line: ' . $e->getLine()); \Log::error('Stack trace: ' . $e->getTraceAsString()); \Log::error('=== PDF UPLOAD DEBUG END (ERROR) ==='); return redirect()->route('admin.docket-entries.show', $docketEntry->id) ->with('error', 'Upload failed: ' . $e->getMessage()); } } /** * Remove the specified document. */ public function destroy(Document $document): RedirectResponse { $docketEntryId = $document->docket_entry_id; // Delete the file from storage if (Storage::disk('public')->exists($document->file_path)) { Storage::disk('public')->delete($document->file_path); } // Delete the database record $document->delete(); return redirect()->route('admin.docket-entries.show', $docketEntryId) ->with('success', 'Document deleted successfully.'); } }