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