Better error handling for qr codes on invalid assets
This commit is contained in:
parent
d1022e8ff7
commit
a3e80882c1
1 changed files with 14 additions and 11 deletions
|
@ -666,20 +666,23 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
if ($settings->qr_code == '1') {
|
if ($settings->qr_code == '1') {
|
||||||
$asset = Asset::withTrashed()->find($assetId);
|
$asset = Asset::withTrashed()->find($assetId);
|
||||||
$size = Helper::barcodeDimensions($settings->barcode_type);
|
if ($asset) {
|
||||||
$qr_file = public_path().'/uploads/barcodes/qr-'.str_slug($asset->asset_tag).'-'.str_slug($asset->id).'.png';
|
$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 (isset($asset->id, $asset->asset_tag)) {
|
||||||
if (file_exists($qr_file)) {
|
if (file_exists($qr_file)) {
|
||||||
$header = ['Content-type' => 'image/png'];
|
$header = ['Content-type' => 'image/png'];
|
||||||
return response()->file($qr_file, $header);
|
return response()->file($qr_file, $header);
|
||||||
} else {
|
} else {
|
||||||
$barcode = new \Com\Tecnick\Barcode\Barcode();
|
$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));
|
$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());
|
file_put_contents($qr_file, $barcode_obj->getPngData());
|
||||||
return response($barcode_obj->getPngData())->header('Content-type', 'image/png');
|
return response($barcode_obj->getPngData())->header('Content-type', 'image/png');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 'That asset is invalid';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue