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(); return $dataTable->render('cetaklabel::app.cardboard-detail.odner', compact('cardboard_id', 'current_odner')); } /** * 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); print_r($documents); foreach ($documents as $document) { $data = [ 'cardboard_id' => $request->cardboard_id, 'document_id' => $document ]; try { CardboardDetail::updateOrCreate($data); echo json_encode(['status' => 'success', 'message' => 'Cardboard created successfully.']); } catch (Exception $e) { echo json_encode(['status' => 'error', 'message' => 'Cardboard created 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(); echo json_encode(['status' => 'success', 'message' => 'Cardboard deleted successfully.']); } }