validate([ 'image_path' => 'required|string', 'quantity' => 'required|integer|min:1', ]); $imagePath = public_path(str_replace(url('/'), '', $request->input('image_path'))); $quantity = $request->input('quantity'); // Retrieve printer name from global settings using standard Eloquent $printerName = \App\Models\Setting::where('key', 'selected_printer')->value('value'); if (!$printerName) { Log::error("PrintController: Default printer name not found in settings."); return response()->json(['error' => 'Default printer not configured.'], 500); } if (!$printerName) { Log::error("PrintController: Default printer name not found in settings."); return response()->json(['error' => 'Default printer not configured.'], 500); } if (!file_exists($imagePath)) { Log::error("PrintController: Image file not found at {$imagePath}"); return response()->json(['error' => 'Image file not found.'], 404); } $printSuccess = $printerService->printImage($imagePath, $printerName, $quantity); if ($printSuccess) { Log::info("PrintController: Successfully sent print command for {$imagePath} (x{$quantity}) to {$printerName}"); return response()->json(['message' => 'Print command sent successfully.']); } else { Log::error("PrintController: Failed to send print command for {$imagePath} (x{$quantity}) to {$printerName}"); return response()->json(['error' => 'Failed to send print command.'], 500); } } }