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