input('perPage', 5); $query = Peti::with(['customer', 'warehouse', 'tipe_peti', 'kondisipeti', 'transfer', 'assetStatuses']) ->orderBy('created_at', 'desc'); // Tambahkan logika pencarian $search = $request->input('search') ?? ''; // Tambahkan logika pencarian $search = $request->input('search') ?? ''; if ($search) { $query->where(function ($q) use ($search) { $q->where('fix_lot', 'like', "%$search%") ->orWhere('created_by', 'like', "%$search%") ->orWhereHas('customer', function ($customerQuery) use ($search) { $customerQuery->where('name', 'like', "%$search%") ->orWhere('code_customer', 'like', "%$search%") ->orWhere('lot_no', 'like', "%$search%"); }) ->orWhereHas('warehouse', function ($warehouseQuery) use ($search) { $warehouseQuery->where('name', 'like', "%$search%"); }) ->orWhereHas('tipe_peti', function ($tipePetiQuery) use ($search) { $tipePetiQuery->where('type', 'like', "%$search%") ->orWhere('size_peti', 'like', "%$search%"); }) ->orWhereHas('kondisipeti', function ($kondisiPetiQuery) use ($search) { $kondisiPetiQuery->where('nama_kondisi', 'like', "%$search%"); }) ->orWhere('packing_no', 'like', "%$search%") ->orWhere('status', 'like', "%$search%"); }); } if ($perPage == 'Semua') { $chunkSize = 100; $petis = new Collection(); $currentPage = 1; $query->chunk($chunkSize, function ($petiChunk) use ($petis, &$currentPage) { foreach ($petiChunk as $peti) { $peti->setAttribute('i', ($currentPage - 1) * $petiChunk->perPage() + 1); $petis->push($peti); $currentPage++; } }); } else { $petis = $query->paginate($perPage); } $data = [ 'peti' => $petis, 'i' => ($petis->currentPage() - 1) * $petis->perPage() + 1, 'search' => $search, 'active' => 'menu-Pettern_Lot_Peti' ]; return view('dashboard.Master_Data.Report.Pattern_lot_peti.index', $data); } public function show($id) { // dd('test'); $data = [ 'peti' => Peti::find($id), 'assetStatus' => asset_status::where('peti_id', $id)->get(), 'active' => 'menu-Pettern_Lot_Peti' ]; return view('dashboard.Master_Data.Report.Pattern_lot_peti.detail_peti', $data); } public function export() { // dd('test'); return Excel::download(new PetternLotPetiExport, 'REPORT_PETI.xlsx'); } }