"Produit trouvé", 2 => "Produit non trouvé", 3 => "Produit élaboré", 4 => "Eleveur non trouvé", 5 => "CP Eleveur manquant" ]; public function index() { $t = Traceability::orderBy('created_at', 'DESC')->paginate(40); $c = $this->countRequest(); $dateDebut = null; $dateFin = null; return view( 'bo.traceability.index', compact('t', 'c', 'dateDebut', 'dateFin') )->with('responseType', $this->responseType); } public function filter(Request $request) { $dateDebut = $request->date_debut; $dateFin = $request->date_fin; $cDateDebut = null; $cDateFin = null; if ($dateDebut !== null) { $cDateDebut = Carbon::createFromFormat('Y-m-d', $dateDebut); } if ($dateFin !== null) { $cDateFin = Carbon::createFromFormat('Y-m-d', $dateFin); } if ($dateDebut !== null && $dateFin !== null) { $t = Traceability::whereBetween('created_at', [$cDateDebut, $cDateFin])->paginate(40); } elseif ($dateDebut !== null) { $t = Traceability::whereDate('created_at', '>=', $cDateDebut)->paginate(40); } elseif ($dateFin !== null) { $t = Traceability::whereDate('created_at', '<=', $cDateFin)->paginate(40); } else { $t = Traceability::all(); } $c = $this->countRequest(); return view( 'bo.traceability.index', compact('t', 'c', 'dateDebut', 'dateFin') )->with('responseType', $this->responseType); } public function countRequest() { $counts = []; $counts[1] = Traceability::where('response_type', 1)->count(); $counts[2] = Traceability::where('response_type', 2)->count(); $counts[3] = Traceability::where('response_type', 3)->count(); $counts[4] = Traceability::where('response_type', 4)->count(); $counts[5] = Traceability::where('response_type', 5)->count(); return $counts; } }