repository = $reason; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Shopping\Returning\Repositories\Criteria\ReasonResourceCriteria::class); } /** * Display a list of reason. * * @return Response */ public function index(ReasonRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Shopping\Returning\Repositories\Presenter\ReasonPresenter::class) ->$function(); } $reasons = $this->repository->paginate(); return $this->response->title(trans('returning::reason.names')) ->view('returning::reason.index', true) ->data(compact('reasons')) ->output(); } /** * Display reason. * * @param Request $request * @param Model $reason * * @return Response */ public function show(ReasonRequest $request, Reason $reason) { if ($reason->exists) { $view = 'returning::reason.show'; } else { $view = 'returning::reason.new'; } return $this->response->title(trans('app.view') . ' ' . trans('returning::reason.name')) ->data(compact('reason')) ->view($view, true) ->output(); } /** * Show the form for creating a new reason. * * @param Request $request * * @return Response */ public function create(ReasonRequest $request) { $reason = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('returning::reason.name')) ->view('returning::reason.create', true) ->data(compact('reason')) ->output(); } /** * Create new reason. * * @param Request $request * * @return Response */ public function store(ReasonRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $reason = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('returning::reason.name')])) ->code(204) ->status('success') ->url(guard_url('returning/reason/' . $reason->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/returning/reason')) ->redirect(); } } /** * Show reason for editing. * * @param Request $request * @param Model $reason * * @return Response */ public function edit(ReasonRequest $request, Reason $reason) { return $this->response->title(trans('app.edit') . ' ' . trans('returning::reason.name')) ->view('returning::reason.edit', true) ->data(compact('reason')) ->output(); } /** * Update the reason. * * @param Request $request * @param Model $reason * * @return Response */ public function update(ReasonRequest $request, Reason $reason) { try { $attributes = $request->all(); $reason->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('returning::reason.name')])) ->code(204) ->status('success') ->url(guard_url('returning/reason/' . $reason->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('returning/reason/' . $reason->getRouteKey())) ->redirect(); } } /** * Remove the reason. * * @param Model $reason * * @return Response */ public function destroy(ReasonRequest $request, Reason $reason) { try { $reason->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('returning::reason.name')])) ->code(202) ->status('success') ->url(guard_url('returning/reason/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('returning/reason/' . $reason->getRouteKey())) ->redirect(); } } /** * Remove multiple reason. * * @param Model $reason * * @return Response */ public function delete(ReasonRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('returning::reason.name')])) ->status("success") ->code(202) ->url(guard_url('returning/reason')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/returning/reason')) ->redirect(); } } /** * Restore deleted reasons. * * @param Model $reason * * @return Response */ public function restore(ReasonRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('returning::reason.name')])) ->status("success") ->code(202) ->url(guard_url('/returning/reason')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/returning/reason/')) ->redirect(); } } }