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