From a3e80882c1ec7b00710648736bfbc14871673d84 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 8 Nov 2017 01:04:14 -0800 Subject: [PATCH] Better error handling for qr codes on invalid assets --- app/Http/Controllers/AssetsController.php | 25 +++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php index 84d891d96..056df24aa 100755 --- a/app/Http/Controllers/AssetsController.php +++ b/app/Http/Controllers/AssetsController.php @@ -666,20 +666,23 @@ class AssetsController extends Controller if ($settings->qr_code == '1') { $asset = Asset::withTrashed()->find($assetId); - $size = Helper::barcodeDimensions($settings->barcode_type); - $qr_file = public_path().'/uploads/barcodes/qr-'.str_slug($asset->asset_tag).'-'.str_slug($asset->id).'.png'; + if ($asset) { + $size = Helper::barcodeDimensions($settings->barcode_type); + $qr_file = public_path().'/uploads/barcodes/qr-'.str_slug($asset->asset_tag).'-'.str_slug($asset->id).'.png'; - if (isset($asset->id, $asset->asset_tag)) { - if (file_exists($qr_file)) { - $header = ['Content-type' => 'image/png']; - return response()->file($qr_file, $header); - } else { - $barcode = new \Com\Tecnick\Barcode\Barcode(); - $barcode_obj = $barcode->getBarcodeObj($settings->barcode_type, route('hardware.show', $asset->id), $size['height'], $size['width'], 'black', array(-2, -2, -2, -2)); - file_put_contents($qr_file, $barcode_obj->getPngData()); - return response($barcode_obj->getPngData())->header('Content-type', 'image/png'); + if (isset($asset->id, $asset->asset_tag)) { + if (file_exists($qr_file)) { + $header = ['Content-type' => 'image/png']; + return response()->file($qr_file, $header); + } else { + $barcode = new \Com\Tecnick\Barcode\Barcode(); + $barcode_obj = $barcode->getBarcodeObj($settings->barcode_type, route('hardware.show', $asset->id), $size['height'], $size['width'], 'black', array(-2, -2, -2, -2)); + file_put_contents($qr_file, $barcode_obj->getPngData()); + return response($barcode_obj->getPngData())->header('Content-type', 'image/png'); + } } } + return 'That asset is invalid'; } }