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