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