repository = $attribute; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Shopping\Product\Repositories\Criteria\AttributeResourceCriteria::class); } /** * Display a list of attribute. * * @return Response */ public function index(AttributeRequest $request) { return $this->repository ->setPresenter(\Shopping\Product\Repositories\Presenter\AttributePresenter::class) ->paginate(); } /** * Display attribute. * * @param Request $request * @param Model $attribute * * @return Response */ public function show(AttributeRequest $request, Attribute $attribute) { return $attribute->setPresenter(\Shopping\Product\Repositories\Presenter\AttributeListPresenter::class); ; } /** * Create new attribute. * * @param Request $request * * @return Response */ public function store(AttributeRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('product::attribute.name')]); $code = 204; $status = 'success'; $url = guard_url('product/attribute/' . $attribute->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('product/attribute'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the attribute. * * @param Request $request * @param Model $attribute * * @return Response */ public function update(AttributeRequest $request, Attribute $attribute) { try { $data = $request->all(); $attribute->update($data); $message = trans('messages.success.updated', ['Module' => trans('product::attribute.name')]); $code = 204; $status = 'success'; $url = guard_url('product/attribute/' . $attribute->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('product/attribute/' . $attribute->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the attribute. * * @param Model $attribute * * @return Response */ public function destroy(AttributeRequest $request, Attribute $attribute) { try { $attribute->delete(); $message = trans('messages.success.deleted', ['Module' => trans('product::attribute.name')]); $code = 202; $status = 'success'; $url = guard_url('product/attribute/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('product/attribute/' . $attribute->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }