m_warehouse::orderBy('created_at', 'desc')->get(), 'active' => 'menu-warehouse', ]; return view('dashboard.Master_Data.Warehouse.index', $data); } /** * Store a newly created resource in storage. */ public function store(ValidasiCreateWarehouse $request) { try { $currentUser = Auth::user(); $validatedData = $request->except('_token'); $validatedData['created_by'] = $currentUser->fullname; $validatedData['updated_by'] = $currentUser->fullname; m_warehouse::create($validatedData); return redirect()->back()->with('success', 'Data gudang berhasil ditambah.'); } catch (\Throwable $th) { return redirect()->back()->with('error', 'Data gudang gagal ditambah.'); } } /** * Update the specified resource in storage. */ public function update(ValidasiUpdateWarehouse $request, $id) { try { $warehouse = m_warehouse::findOrFail($id); $warehouse->update($request->all()); // Menambahkan nama pengguna yang melakukan pembaruan $userData['updated_by'] = Auth::user()->fullname; return redirect()->back()->with('success', 'Data Gudang Berhasil Diperbaharui'); } catch (\Throwable $th) { return redirect()->back()->with('error', 'Data Gudang Gagal Diperbaharui'); } } /** * Remove the specified resource from storage. */ public function destroy($id) { // dd("oke"); try { $asset = m_warehouse::findOrFail($id); $asset->delete(); return redirect()->back()->with('success', 'Data Gudang berhasil dihapus'); } catch (\Throwable $th) { return redirect()->back()->with('error', 'Data Gudang gagal dihapus'); } } public function importWarehouse(Request $request) { $import = new WarehouseImport; try { Excel::import($import, request()->file('file')); if ($import->getRowCount() > 0) { return redirect()->route('dashboard.warehouse.index')->with('success', 'Data Warehouse berhasil diimport'); } else { $errors = $import->getErrors(); if (!empty($errors)) { session()->flash('error', $errors); } return redirect()->back()->with('import', $import)->with('error', 'Data Warehouse gagal di import.'); } } catch (\Maatwebsite\Excel\Validators\ValidationException $e) { $failures = $e->failures(); foreach ($failures as $failure) { session()->flash('error', ['Baris ' . $failure->row() => implode(', ', $failure->errors())]); } } } }