addres qoshish da api o'zgartirildi
This commit is contained in:
@@ -53,13 +53,27 @@ class QrController extends Controller
|
||||
|
||||
public static function generateQr($id, $type)
|
||||
{
|
||||
// type is 'auto_' or 'estate_'
|
||||
try {
|
||||
$cleanType = str_replace('_', '', $type);
|
||||
$url = route('qr.verify', ['type' => $cleanType, 'id' => $id]);
|
||||
$dir = 'public/attachments/' . $type . $id;
|
||||
Storage::makeDirectory($dir);
|
||||
$absDir = storage_path('app/' . $dir);
|
||||
|
||||
if (!is_dir($absDir)) {
|
||||
mkdir($absDir, 0755, true);
|
||||
} else {
|
||||
chmod($absDir, 0755);
|
||||
}
|
||||
|
||||
$qr = QrCode::format('png')->size(200)->generate($url);
|
||||
Storage::put($dir . '/qr.png', $qr);
|
||||
$qrPath = $absDir . '/qr.png';
|
||||
file_put_contents($qrPath, $qr);
|
||||
chmod($qrPath, 0644);
|
||||
} catch (\Exception $e) {
|
||||
\Illuminate\Support\Facades\Log::error('QR generate failed: ' . $e->getMessage(), [
|
||||
'id' => $id, 'type' => $type,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function qrImage($type, $id)
|
||||
@@ -67,6 +81,10 @@ class QrController extends Controller
|
||||
$dbType = $type === 'auto' ? 'auto_' : 'estate_';
|
||||
$path = storage_path('app/public/attachments/' . $dbType . $id . '/qr.png');
|
||||
|
||||
if (!file_exists($path)) {
|
||||
self::generateQr($id, $dbType);
|
||||
}
|
||||
|
||||
if (!file_exists($path)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user