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