repository = $cart; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Ebuy\Cart\Repositories\Criteria\CartResourceCriteria::class); } /** * Display a list of cart. * * @return Response */ public function index(CartRequest $request) { return $this->repository ->setPresenter(\Ebuy\Cart\Repositories\Presenter\CartPresenter::class) ->paginate(); } /** * Display cart. * * @param Request $request * @param Model $cart * * @return Response */ public function show(CartRequest $request, Cart $cart) { return $cart->setPresenter(\Ebuy\Cart\Repositories\Presenter\CartListPresenter::class); ; } /** * Create new cart. * * @param Request $request * * @return Response */ public function store(CartRequest $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('cart::cart.name')]); $code = 204; $status = 'success'; $url = guard_url('cart/cart/' . $cart->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('cart/cart'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the cart. * * @param Request $request * @param Model $cart * * @return Response */ public function update(CartRequest $request, Cart $cart) { try { $data = $request->all(); $cart->update($data); $message = trans('messages.success.updated', ['Module' => trans('cart::cart.name')]); $code = 204; $status = 'success'; $url = guard_url('cart/cart/' . $cart->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('cart/cart/' . $cart->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the cart. * * @param Model $cart * * @return Response */ public function destroy(CartRequest $request, Cart $cart) { try { $cart->delete(); $message = trans('messages.success.deleted', ['Module' => trans('cart::cart.name')]); $code = 202; $status = 'success'; $url = guard_url('cart/cart/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('cart/cart/' . $cart->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); } }