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