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