repository = $membership; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litepie\Member\Repositories\Criteria\MembershipResourceCriteria::class); } /** * Display a list of membership. * * @return Response */ public function index(MembershipRequest $request) { return $this->repository ->setPresenter(\Litepie\Member\Repositories\Presenter\MembershipPresenter::class) ->paginate(); } /** * Display membership. * * @param Request $request * @param Model $membership * * @return Response */ public function show(MembershipRequest $request, Membership $membership) { return $membership->setPresenter(\Litepie\Member\Repositories\Presenter\MembershipListPresenter::class); ; } /** * Create new membership. * * @param Request $request * * @return Response */ public function store(MembershipRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('member::membership.name')]); $code = 204; $status = 'success'; $url = guard_url('member/membership/' . $membership->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('member/membership'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the membership. * * @param Request $request * @param Model $membership * * @return Response */ public function update(MembershipRequest $request, Membership $membership) { try { $data = $request->all(); $membership->update($data); $message = trans('messages.success.updated', ['Module' => trans('member::membership.name')]); $code = 204; $status = 'success'; $url = guard_url('member/membership/' . $membership->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('member/membership/' . $membership->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the membership. * * @param Model $membership * * @return Response */ public function destroy(MembershipRequest $request, Membership $membership) { try { $membership->delete(); $message = trans('messages.success.deleted', ['Module' => trans('member::membership.name')]); $code = 202; $status = 'success'; $url = guard_url('member/membership/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('member/membership/' . $membership->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }