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