Add comprehensive debug logging for PDF upload
- Added detailed logging at each step of upload process - Logs file info, validation, storage, and database creation - Catches and logs full exception details with stack trace - Will help diagnose 500 error on PDF upload
This commit is contained in:
parent
6f66e0987a
commit
b2b061b57a
1 changed files with 64 additions and 31 deletions
|
|
@ -17,39 +17,72 @@ class DocumentController extends Controller
|
|||
*/
|
||||
public function store(Request $request, DocketEntry $docketEntry): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'file' => 'required|file|mimes:pdf|max:512000', // 500MB max
|
||||
'title' => 'required|string|max:255',
|
||||
'summary' => 'nullable|string',
|
||||
]);
|
||||
try {
|
||||
\Log::info('=== PDF UPLOAD DEBUG START ===');
|
||||
\Log::info('Docket Entry ID: ' . $docketEntry->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'));
|
||||
}
|
||||
|
||||
// Get the uploaded file
|
||||
$file = $request->file('file');
|
||||
|
||||
// Generate unique filename
|
||||
$storedFilename = Str::uuid() . '.pdf';
|
||||
|
||||
// Store file in storage/app/public/documents
|
||||
$filePath = $file->storeAs('documents', $storedFilename, 'public');
|
||||
|
||||
// Get the highest display order for this entry
|
||||
$maxOrder = $docketEntry->documents()->max('display_order') ?? -1;
|
||||
|
||||
// Create document record
|
||||
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,
|
||||
]);
|
||||
$validated = $request->validate([
|
||||
'file' => 'required|file|mimes:pdf|max:512000', // 500MB max
|
||||
'title' => 'required|string|max:255',
|
||||
'summary' => 'nullable|string',
|
||||
]);
|
||||
\Log::info('Validation passed');
|
||||
|
||||
return redirect()->route('admin.docket-entries.show', $docketEntry->id)
|
||||
->with('success', 'Document uploaded successfully.');
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue