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