ajax()) { $data = ShipTo::select('*'); return Datatables::of($data) ->addIndexColumn() ->addColumn('checkbox', function () { return ''; }) ->addColumn('action', function ($row) { $actionBtn = 'Edit '; $actionBtn .= '
'; return $actionBtn; }) ->rawColumns(['checkbox', 'action']) ->make(true); } return view('m3::liberty-theme.pages.ship-to.index'); } public function create() { // US $uSstates = USStates::all(); // CA $cAstates = CAProvinces::all(); // All States $states = array_merge($uSstates, $cAstates); return view('m3::liberty-theme.pages.ship-to.create', compact('states')); } public function store(Request $request) { $validated = $request->validate( [ 'AUSTCN' => 'nullable|max:11', 'AUSHSHNM' => 'required|max:36', 'AUSHSHA1' => 'required|max:36', 'AUSHSHA2' => 'required|max:36', 'AUSHSHA3' => 'nullable|max:36', 'AUSHSHA4' => 'nullable|max:36', 'AUSHSHCI' => 'required|max:20', 'AUSHSHST' => 'required|max:2', 'AUSHSHZP' => 'required|max:10', 'AUSHSHCT' => 'required|max:3', 'AUSHWHS' => 'required|max:3', ], [ 'AUSHSHNM.required' => 'Name is required', 'AUSHSHA1.required' => 'Address 1 is required', 'AUSHSHA2.required' => 'Address 2 is required', 'AUSHSHCI.required' => 'City is required', 'AUSHSHST.required' => 'State is required', 'AUSHSHZP.required' => 'Zip code is required', 'AUSHSHCT.required' => 'Country is required', 'AUSHWHS.required' => 'Warehouse is required', 'AUSTCN.max' => 'Customer Number cannot exceed 11 characters', 'AUSHSHNM.max' => 'Name cannot exceed 36 characters', 'AUSHSHA1.max' => 'Address 1 cannot exceed 36 characters', 'AUSHSHA2.max' => 'Address 2 cannot exceed 36 characters', 'AUSHSHA3.max' => 'Address 3 cannot exceed 36 characters', 'AUSHSHA4.max' => 'Address 4 cannot exceed 36 characters', 'AUSHSHCI.max' => 'City cannot exceed 20 characters', 'AUSHSHST.max' => 'State cannot exceed 2 characters', 'AUSHSHZP.max' => 'Zip code cannot exceed 10 characters', 'AUSHSHCT.max' => 'Country cannot exceed 3 characters', 'AUSHWHS.max' => 'Warehouse cannot exceed 3 characters', ], ); $validated['AUSTCN'] = $validated['AUSTCN'] ?? ' '; $model = new ShipTo; $model->fill($validated); $success = $model->save(); if ($success) { return redirect()->route('m3.ship-to.index')->with('success', 'Record created successfully.'); } else { return redirect()->back() ->withErrors(['unique' => 'The combination of ZipCode and Warehouse must be unique.']) ->withInput(); } } public function edit($aushshzp, $aushwhs) { // US $uSstates = USStates::all(); // CA $cAstates = CAProvinces::all(); // All States $states = array_merge($uSstates, $cAstates); $shipTo = ShipTo::where('AUSHSHZP', $aushshzp) ->where('AUSHWHS', $aushwhs) ->firstOrFail(); return view('m3::liberty-theme.pages.ship-to.edit', compact('shipTo', 'states')); } public function update(Request $request, $aushshzp, $aushwhs) { $validated = array_map(function ($value) { return $value === null ? '' : $value; }, $request->validate( [ 'AUSTCN' => 'nullable|string|max:11', 'AUSHSHNM' => 'required|max:36', 'AUSHSHA1' => 'required|max:36', 'AUSHSHA2' => 'required|max:36', 'AUSHSHA3' => 'nullable|string|max:36', 'AUSHSHA4' => 'nullable|string|max:36', 'AUSHSHCI' => 'required|max:20', 'AUSHSHST' => 'required|max:2', 'AUSHSHCT' => 'required|max:3', ], [ 'AUSHSHNM.required' => 'Name is required', 'AUSHSHA1.required' => 'Address 1 is required', 'AUSHSHA2.required' => 'Address 2 is required', 'AUSHSHCI.required' => 'City is required', 'AUSHSHST.required' => 'State is required', 'AUSHSHZP.required' => 'Zip code is required', 'AUSHSHCT.required' => 'Country is required', 'AUSHWHS.required' => 'Warehouse is required', 'AUSTCN.max' => 'Customer Number cannot exceed 11 characters', 'AUSHSHNM.max' => 'Name cannot exceed 36 characters', 'AUSHSHA1.max' => 'Address 1 cannot exceed 36 characters', 'AUSHSHA2.max' => 'Address 2 cannot exceed 36 characters', 'AUSHSHA3.max' => 'Address 3 cannot exceed 36 characters', 'AUSHSHA4.max' => 'Address 4 cannot exceed 36 characters', 'AUSHSHCI.max' => 'City cannot exceed 20 characters', 'AUSHSHST.max' => 'State cannot exceed 2 characters', 'AUSHSHZP.max' => 'Zip code cannot exceed 10 characters', 'AUSHSHCT.max' => 'Country cannot exceed 3 characters', 'AUSHWHS.max' => 'Warehouse cannot exceed 3 characters', ], )); $updated = ShipTo::where('AUSHSHZP', $aushshzp) ->where('AUSHWHS', $aushwhs) ->update($validated); if ($updated) { return redirect()->route('m3.ship-to.index')->with('success', 'Record updated successfully.'); } else { return redirect()->route('m3.ship-to.index')->with('error', 'Record could not be updated.'); } } public function destroy($aushshzp, $aushwhs) { $deleted = ShipTo::where('AUSHSHZP', $aushshzp) ->where('AUSHWHS', $aushwhs) ->delete(); if ($deleted) { return redirect()->route('m3.ship-to.index')->with('success', 'Record deleted successfully.'); } else { return redirect()->route('m3.ship-to.index')->with('error', 'Record not found or could not be deleted.'); } } }