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