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