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