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