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,26 +17,45 @@ class DocumentController extends Controller
|
||||||
*/
|
*/
|
||||||
public function store(Request $request, DocketEntry $docketEntry): RedirectResponse
|
public function store(Request $request, DocketEntry $docketEntry): RedirectResponse
|
||||||
{
|
{
|
||||||
|
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'));
|
||||||
|
}
|
||||||
|
|
||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
'file' => 'required|file|mimes:pdf|max:512000', // 500MB max
|
'file' => 'required|file|mimes:pdf|max:512000', // 500MB max
|
||||||
'title' => 'required|string|max:255',
|
'title' => 'required|string|max:255',
|
||||||
'summary' => 'nullable|string',
|
'summary' => 'nullable|string',
|
||||||
]);
|
]);
|
||||||
|
\Log::info('Validation passed');
|
||||||
|
|
||||||
// Get the uploaded file
|
// Get the uploaded file
|
||||||
$file = $request->file('file');
|
$file = $request->file('file');
|
||||||
|
|
||||||
// Generate unique filename
|
// Generate unique filename
|
||||||
$storedFilename = Str::uuid() . '.pdf';
|
$storedFilename = Str::uuid() . '.pdf';
|
||||||
|
\Log::info('Generated filename: ' . $storedFilename);
|
||||||
|
|
||||||
// Store file in storage/app/public/documents
|
// Store file in storage/app/public/documents
|
||||||
|
\Log::info('Attempting to store file...');
|
||||||
$filePath = $file->storeAs('documents', $storedFilename, 'public');
|
$filePath = $file->storeAs('documents', $storedFilename, 'public');
|
||||||
|
\Log::info('File stored at: ' . $filePath);
|
||||||
|
|
||||||
// Get the highest display order for this entry
|
// Get the highest display order for this entry
|
||||||
$maxOrder = $docketEntry->documents()->max('display_order') ?? -1;
|
$maxOrder = $docketEntry->documents()->max('display_order') ?? -1;
|
||||||
|
\Log::info('Max display order: ' . $maxOrder);
|
||||||
|
|
||||||
// Create document record
|
// Create document record
|
||||||
Document::create([
|
\Log::info('Creating document record...');
|
||||||
|
$document = Document::create([
|
||||||
'docket_entry_id' => $docketEntry->id,
|
'docket_entry_id' => $docketEntry->id,
|
||||||
'title' => $validated['title'],
|
'title' => $validated['title'],
|
||||||
'original_filename' => $file->getClientOriginalName(),
|
'original_filename' => $file->getClientOriginalName(),
|
||||||
|
|
@ -47,9 +66,23 @@ class DocumentController extends Controller
|
||||||
'summary' => $validated['summary'] ?? null,
|
'summary' => $validated['summary'] ?? null,
|
||||||
'display_order' => $maxOrder + 1,
|
'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)
|
return redirect()->route('admin.docket-entries.show', $docketEntry->id)
|
||||||
->with('success', 'Document uploaded successfully.');
|
->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