middleware(function ($request, $next) { $this->user = Auth::guard('web')->user(); return $next($request); }); } /** * Display a listing of the Sub Jobs. * * @param \Modules\Cetaklabel\DataTables\SubJobDataTable $dataTable * @param \Illuminate\Http\Request $request * * @return mixed|void */ public function index(SubJobDataTable $dataTable, Request $request) { if (is_null($this->user) || !$this->user->can('masters.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } addVendor('chained-select'); if (isset($request->job_id) && !empty($request->job_id)) { $this->show($request); return; } $directorat = Directorat::all(); return $dataTable->render('cetaklabel::masters.sub-job.index', compact('directorat')); } /** * Lists the specified Sub Job by Job ID. * * @param \Illuminate\Http\Request $request * * @return void */ public function show(Request $request) { if (is_null($this->user) || !$this->user->can('masters.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } $subJob = SubJob::where('job_id', $request->job_id)->get(); $data = []; foreach ($subJob as $row) { $result = [ $row->id => $row->name, ]; $data[] = $result; } echo json_encode($data); } /** * Store a newly created Sub Job in storage. * * @param \Modules\Cetaklabel\Http\Requests\SubJob\StoreSubJobRequest $request * * @return void */ public function store(StoreSubJobRequest $request) { if (is_null($this->user) || !$this->user->can('masters.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } // Validate the request... $validated = $request->validated(); // Store the SubJob... if ($validated) { try { SubJob::create($validated); echo json_encode(['status' => 'success', 'message' => 'Sub Job created successfully.']); } catch (Exception $e) { echo json_encode(['status' => 'error', 'message' => 'Sub Job created failed.']); } return; } echo json_encode(['status' => 'error', 'message' => 'Sub Job created failed.']); } /** * Show the form for creating a new Sub Job. * * @return void */ public function create() { if (is_null($this->user) || !$this->user->can('masters.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } abort(404); } /** * Show the form for editing the specified Sub Job. * * @param $id * * @return void */ public function edit($id) { if (is_null($this->user) || !$this->user->can('masters.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } $subJob = SubJob::find($id); echo json_encode($subJob); } /** * Update the specified Sub Job in storage. * * @param \Modules\Cetaklabel\Http\Requests\SubJob\UpdateSubJobRequest $request * @param \Modules\Cetaklabel\Entities\SubJob $subJob * * @return false */ public function update(UpdateSubJobRequest $request, SubJob $subJob) { if (is_null($this->user) || !$this->user->can('masters.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } // Validate the request... $validated = $request->validated(); // Update the SubJob... if ($validated) { try { $subJob->update($validated); echo json_encode(['status' => 'success', 'message' => 'Sub Job updated successfully.']); } catch (Exception $e) { echo json_encode(['status' => 'error', 'message' => 'Sub Job updated failed.']); } return; } echo json_encode(['status' => 'error', 'message' => 'Sub Job updated failed.']); } /** * Remove the specified Sub Job from storage. * * @param \Modules\Cetaklabel\Entities\SubJob $subJob * * @return void */ public function destroy(SubJob $subJob) { if (is_null($this->user) || !$this->user->can('masters.delete')) { abort(403, 'Sorry !! You are Unauthorized to delete any master data !'); } $subJob->delete(); echo json_encode(['status' => 'success', 'message' => 'Sub Job deleted successfully.']); } }