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