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