repository = $supervisor; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Focus\Supervisor\Repositories\Criteria\SupervisorResourceCriteria::class); } /** * Display a list of supervisor. * * @return Response */ public function index(SupervisorRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Focus\Supervisor\Repositories\Presenter\SupervisorPresenter::class) ->$function(); } $supervisors = $this->repository->paginate(); return $this->response->title(trans('supervisor::supervisor.names')) ->view('supervisor::supervisor.index', true) ->data(compact('supervisors')) ->output(); } /** * Display supervisor. * * @param Request $request * @param Model $supervisor * * @return Response */ public function show(SupervisorRequest $request, Supervisor $supervisor) { if ($supervisor->exists) { $view = 'supervisor::supervisor.show'; } else { $view = 'supervisor::supervisor.new'; } return $this->response->title(trans('app.view') . ' ' . trans('supervisor::supervisor.name')) ->data(compact('supervisor')) ->view($view, true) ->output(); } /** * Show the form for creating a new supervisor. * * @param Request $request * * @return Response */ public function create(SupervisorRequest $request) { $supervisor = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('supervisor::supervisor.name')) ->view('supervisor::supervisor.create', true) ->data(compact('supervisor')) ->output(); } /** * Create new supervisor. * * @param Request $request * * @return Response */ public function store(SupervisorRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $supervisor = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('supervisor::supervisor.name')])) ->code(204) ->status('success') ->url(guard_url('supervisor/supervisor/' . $supervisor->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/supervisor/supervisor')) ->redirect(); } } /** * Show supervisor for editing. * * @param Request $request * @param Model $supervisor * * @return Response */ public function edit(SupervisorRequest $request, Supervisor $supervisor) { return $this->response->title(trans('app.edit') . ' ' . trans('supervisor::supervisor.name')) ->view('supervisor::supervisor.edit', true) ->data(compact('supervisor')) ->output(); } /** * Update the supervisor. * * @param Request $request * @param Model $supervisor * * @return Response */ public function update(SupervisorRequest $request, Supervisor $supervisor) { try { $attributes = $request->all(); $supervisor->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('supervisor::supervisor.name')])) ->code(204) ->status('success') ->url(guard_url('supervisor/supervisor/' . $supervisor->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('supervisor/supervisor/' . $supervisor->getRouteKey())) ->redirect(); } } /** * Remove the supervisor. * * @param Model $supervisor * * @return Response */ public function destroy(SupervisorRequest $request, Supervisor $supervisor) { try { $supervisor->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('supervisor::supervisor.name')])) ->code(202) ->status('success') ->url(guard_url('supervisor/supervisor/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('supervisor/supervisor/' . $supervisor->getRouteKey())) ->redirect(); } } /** * Remove multiple supervisor. * * @param Model $supervisor * * @return Response */ public function delete(SupervisorRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('supervisor::supervisor.name')])) ->status("success") ->code(202) ->url(guard_url('supervisor/supervisor')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/supervisor/supervisor')) ->redirect(); } } /** * Restore deleted supervisors. * * @param Model $supervisor * * @return Response */ public function restore(SupervisorRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('supervisor::supervisor.name')])) ->status("success") ->code(202) ->url(guard_url('/supervisor/supervisor')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/supervisor/supervisor/')) ->redirect(); } } }