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