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