repository = $users; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Moblyze\Plan\Repositories\Criteria\UsersResourceCriteria::class); } /** * Display a list of users. * * @return Response */ public function index(UsersRequest $request) { return $this->repository ->setPresenter(\Moblyze\Plan\Repositories\Presenter\UsersPresenter::class) ->paginate(); } /** * Display users. * * @param Request $request * @param Model $users * * @return Response */ public function show(UsersRequest $request, Users $users) { return $users->setPresenter(\Moblyze\Plan\Repositories\Presenter\UsersListPresenter::class); ; } /** * Create new users. * * @param Request $request * * @return Response */ public function store(UsersRequest $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('plan::users.name')]); $code = 204; $status = 'success'; $url = guard_url('plan/users/' . $users->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('plan/users'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the users. * * @param Request $request * @param Model $users * * @return Response */ public function update(UsersRequest $request, Users $users) { try { $data = $request->all(); $users->update($data); $message = trans('messages.success.updated', ['Module' => trans('plan::users.name')]); $code = 204; $status = 'success'; $url = guard_url('plan/users/' . $users->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('plan/users/' . $users->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the users. * * @param Model $users * * @return Response */ public function destroy(UsersRequest $request, Users $users) { try { $users->delete(); $message = trans('messages.success.deleted', ['Module' => trans('plan::users.name')]); $code = 202; $status = 'success'; $url = guard_url('plan/users/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('plan/users/' . $users->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); } }