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