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