where('id', $id)->first(); if (!$order) { abort(404); } // Add display relations and formatting $order->customer = $order->ordered_customer; $order->purposeOne = \Illuminate\Support\Facades\DB::table('purposes')->where('id', $order->purpose_id)->first(); if ($type === 'auto') { $order->concernOne = \Illuminate\Support\Facades\DB::table('concerns')->where('id', $order->car_category)->first(); $order->ownerName = trim($order->owner_last_name . ' ' . $order->owner_first_name . ' ' . $order->owner_patronymic); $order->name = $order->car_mark; } else { $order->regions = \Illuminate\Support\Facades\DB::table('regions')->where('id', $order->region)->first(); $order->districts = \Illuminate\Support\Facades\DB::table('districts')->where('id', $order->district)->first(); $order->owner = trim($order->owner_last_name . ' ' . $order->owner_first_name . ' ' . $order->owner_patronymic); $order->name = $order->name_of_object; } $conclusion = \Illuminate\Support\Facades\DB::table('files') ->where('order_id', $id) ->where('order_type', 'conclusion_') ->first(); return view('qr.' . $type, compact('order', 'conclusion')); } public function reGenerate($id, $type) { self::generateQr($id, $type); return redirect()->back(); } public static function generateQr($id, $type) { // type is 'auto_' or 'estate_' $cleanType = str_replace('_', '', $type); $url = route('qr.verify', ['type' => $cleanType, 'id' => $id]); $dir = 'public/attachments/' . $type . $id; Storage::makeDirectory($dir); $qr = QrCode::format('png')->size(200)->generate($url); Storage::put($dir . '/qr.png', $qr); } }