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