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