middleware(function ($request, $next) { $this->user = Auth::guard('web')->user(); return $next($request); }); } /** * Display a listing of the Directorats. * * @param \App\DataTables\DirectoratDataTable $dataTable * * @return mixed */ public function index(DirectoratDataTable $dataTable, Request $request) { if (is_null($this->user) || !$this->user->can('master.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } return $dataTable->render('cetaklabel::masters.directorat.index'); } /** * Store a newly created Directorat in storage. * * @param \App\Http\Requests\StoreDirectoratRequest $request * * @return mixed */ public function store(StoreDirectoratRequest $request) { if (is_null($this->user) || !$this->user->can('master.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } // Validate the request... $validated = $request->validated(); // Store the Directorat... if ($validated) { try { Directorat::create($validated); echo json_encode(['status' => 'success', 'message' => 'Directorat created successfully.']); } catch (Exception $e) { echo json_encode(['status' => 'error', 'message' => 'Directorat created failed.']); } return; } echo json_encode(['status' => 'error', 'message' => 'Directorat created failed.']); } /** * Show the form for creating a new Directorat. */ public function create() { if (is_null($this->user) || !$this->user->can('master.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } abort(404); } /** * Display the specified Directorat. * * @param \Modules\Cetaklabel\Entities\Directorat $directorat */ public function show(Directorat $directorat) { if (is_null($this->user) || !$this->user->can('master.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } } /** * Show the form for editing the specified Directorat. * * @param $id */ public function edit($id) { if (is_null($this->user) || !$this->user->can('master.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } $directorat = Directorat::find($id); echo json_encode($directorat); } /** * Update the specified Directorat in storage. * * @param \App\Http\Requests\UpdateDirectoratRequest $request * @param \Modules\Cetaklabel\Entities\Directorat $directorat * * @return mixed */ public function update(UpdateDirectoratRequest $request, Directorat $directorat) { if (is_null($this->user) || !$this->user->can('master.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } // Validate the request... $validated = $request->validated(); // Update the Directorat... if ($validated) { try { $directorat->update($validated); echo json_encode(['status' => 'success', 'message' => 'Directorat updated successfully.']); } catch (Exception $e) { echo json_encode(['status' => 'error', 'message' => 'Directorat updated failed.']); } return; } echo json_encode(['status' => 'error', 'message' => 'Directorat updated failed.']); } /** * Remove the specified Directorat from storage. * * @param \Modules\Cetaklabel\Entities\Directorat $directorat * * @return void */ public function destroy(Directorat $directorat) { if (is_null($this->user) || !$this->user->can('master.delete')) { abort(403, 'Sorry !! You are Unauthorized to delete any master data !'); } $directorat->delete(); echo json_encode(['status' => 'success', 'message' => 'Directorat deleted successfully.']); } }