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