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