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