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