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