middleware(function ($request, $next) { $this->user = Auth::guard('web')->user(); return $next($request); }); } /** * Display a listing of the Cardboards. * * @param \App\DataTables\CardboardDetailDataTable $dataTable * * @return mixed */ public function index(CardboardOdnerDataTable $dataTable, Request $request) { if (is_null($this->user) || !$this->user->can('document.read')) { abort(403, 'Sorry !! You are Unauthorized to view any document data !'); } $cardboard_id = $request->id; $current_odner = CardboardDetail::where('cardboard_id', $cardboard_id)->count(); $odners = CardboardDetail::where('cardboard_id', $cardboard_id)->pluck('document_id')->toArray(); $odners = json_encode($odners); return $dataTable->render('cetaklabel::app.cardboard-detail.odner', compact('cardboard_id', 'current_odner', 'odners')); } /** * Store a newly created Cardboard in storage. * * @return mixed */ public function store(Request $request) { if (is_null($this->user) || !$this->user->can('document.create')) { abort(403, 'Sorry !! You are Unauthorized to create any document data !'); } $documents = explode(',', $request->document_id); $_old = CardboardDetail::where('cardboard_id', $request->cardboard_id)->pluck('document_id')->toArray(); $data = [ 'cardboard_id' => $request->cardboard_id, 'document_id' => $documents ]; $old = [ 'cardboard_id' => $request->cardboard_id, 'document_id' => $_old ]; try { $approval = [ 'method' => 'create', 'menu' => 'CardboardDetail', 'new_request' => json_encode($data), 'old_request' => json_encode($old), 'description' => 'Add or Update Odner Dus', 'status' => '0', ]; Approval::create($approval); echo json_encode(['status' => 'success', 'message' => 'Odner added successfully.']); } catch (Exception $e) { echo json_encode(['status' => 'error', 'message' => 'Odner added failed.']); } } /** * Show the form for creating a new Cardboard. */ public function create() { if (is_null($this->user) || !$this->user->can('document.create')) { abort(403, 'Sorry !! You are Unauthorized to create any document data !'); } abort(404); } /** * Display the specified Cardboard. * * @param \Modules\Cetaklabel\Entities\CardboardDetail $cardboard_detail */ public function show(CardboardDetailDataTable $dataTable) { if (is_null($this->user) || !$this->user->can('document.read')) { abort(403, 'Sorry !! You are Unauthorized to view any document data !'); } return $dataTable->render('cetaklabel::app.cardboard-detail.index'); } /** * Show the form for editing the specified Cardboard. * * @param $id */ public function edit($id) { if (is_null($this->user) || !$this->user->can('document.update')) { abort(403, 'Sorry !! You are Unauthorized to update any document data !'); } $cardboard = CardboardDetail::find($id); echo json_encode($cardboard); } /** * Update the specified Cardboard in storage. * * @param \Modules\Cetaklabel\Entities\CardboardDetail $cardboard_detail * * @return mixed */ public function update(Request $request, CardboardDetail $cardboard_detail) { if (is_null($this->user) || !$this->user->can('document.update')) { abort(403, 'Sorry !! You are Unauthorized to update any document data !'); } // Validate the request... $validated = $request->validated(); // Update the Cardboard... if ($validated) { try { $cardboard_detail->update($validated); echo json_encode(['status' => 'success', 'message' => 'Cardboard updated successfully.']); } catch (Exception $e) { echo json_encode(['status' => 'error', 'message' => 'Cardboard updated failed.']); } return; } echo json_encode(['status' => 'error', 'message' => 'Cardboard updated failed.']); } /** * Remove the specified Cardboard from storage. * * @param \Modules\Cetaklabel\Entities\CardboardDetail $cardboard_detail * * @return void */ public function destroy(CardboardDetail $cardboard_detail) { if (is_null($this->user) || !$this->user->can('document.delete')) { abort(403, 'Sorry !! You are Unauthorized to delete any document data !'); } //$cardboard_detail->delete(); $approval = [ 'method' => 'delete', 'menu' => 'CardboardDetail', 'new_request' => null, 'old_request' => json_encode($cardboard_detail), 'description' => 'Delete Odner Dus', 'status' => '0', ]; Approval::create($approval); echo json_encode(['status' => 'success', 'message' => 'Cardboard deleted successfully.']); } }