codelot) ->where(function ($q) use ($request) { if ($request->eancode[0] === "0") { $code = Str::substr($request->eancode, 1); $q->where('barcode_price', 'LIKE', Str::limit($code, 6, '') . '%') ->orWhere('barcode_weight', 'LIKE', Str::limit($code, 6, '') . '%'); } else { $q->where('barcode_price', 'LIKE', Str::limit($request->eancode, 7, '') . '%') ->orWhere('barcode_weight', 'LIKE', Str::limit($request->eancode, 7, '') . '%'); } })->first(); if (!$traceaPoultry) { return back()->with( 'warning', // phpcs:ignore Generic.Files.LineLength.TooLong trans('Aucun produit n\'a pu être trouvé avec ces informations. Vérifiez bien les numéros saisis avec les indications comme sur l\'image ci-dessous.') ); } Session::put('poultrySearch', [ 'model' => $traceaPoultry, 'time' => now() ]); // * Flash session with age max show result page to 6 return response()->redirectToRoute('poultry.show'); } /** * Show Traceapoultry result * * @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory */ public function show() { // * If result too old or not found /** @var \App\Models\TraceaPoultry|null */ if ( !($traceaPoultry = Session::get('poultrySearch.model')) or !\is_object(Session::get('poultrySearch.time')) or \get_class(Session::get('poultrySearch.time')) !== Carbon::class ) { Session::forget('poultrySearch'); \redirect()->route('poultry.search')->throwResponse(); } $distributionPicture = $this->getDistributionPicture($traceaPoultry->sign); // ! Test that food and mep are available if (!$traceaPoultry->mep or !$traceaPoultry->food) { return \view('front.poultry.unavailable'); } return view('front.poultry.show', compact( 'traceaPoultry', 'distributionPicture' )); } /** * Get distribution sign picture name if exists. * * @param string|null $sign * @return string|null */ private function getDistributionPicture(?string $sign): ?string { if (\is_null($sign) or empty($sign)) { return null; } if (File::exists(\public_path("assets/images/signs/$sign.png"))) { return "$sign.png"; } report(new \RuntimeException("$sign is missing in assets/images/signs")); return null; } }