middleware('web'); $this->middleware('auth:admin.web'); $this->setupTheme(config('theme.themes.admin.theme'), config('theme.themes.admin.layout')); $this->repository = $user; parent::__construct(); } /** * Display a list of user. * * @return Response */ public function index(UserAdminWebRequest $request) { $pageLimit = $request->input('pageLimit'); if ($request->wantsJson()) { $users = $this->repository ->pushCriteria(new \Sample\User\Repositories\Criteria\UserAdminCriteria()) ->setPresenter('\\Sample\\User\\Repositories\\Presenter\\UserListPresenter') ->scopeQuery(function ($query) { return $query->orderBy('id', 'DESC'); })->paginate($pageLimit); $users['recordsTotal'] = $users['meta']['pagination']['total']; $users['recordsFiltered'] = $users['meta']['pagination']['total']; $users['request'] = $request->all(); return response()->json($users, 200); } $this ->theme->prependTitle(trans('user::user.names').' :: '); return $this->theme->of('user::admin.user.index')->render(); } /** * Display user. * * @param Request $request * @param Model $user * * @return Response */ public function show(UserAdminWebRequest $request, User $user) { if (!$user->exists) { return response()->view('user::admin.user.new', compact('user')); } Form::populate($user); return response()->view('user::admin.user.show', compact('user')); } /** * Show the form for creating a new user. * * @param Request $request * * @return Response */ public function create(UserAdminWebRequest $request) { $user = $this->repository->newInstance([]); Form::populate($user); return response()->view('user::admin.user.create', compact('user')); } /** * Create new user. * * @param Request $request * * @return Response */ public function store(UserAdminWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $user = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('user::user.name')]), 'code' => 204, 'redirect' => trans_url('/admin/user/user/'.$user->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show user for editing. * * @param Request $request * @param Model $user * * @return Response */ public function edit(UserAdminWebRequest $request, User $user) { Form::populate($user); return response()->view('user::admin.user.edit', compact('user')); } /** * Update the user. * * @param Request $request * @param Model $user * * @return Response */ public function update(UserAdminWebRequest $request, User $user) { try { $attributes = $request->all(); $user->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('user::user.name')]), 'code' => 204, 'redirect' => trans_url('/admin/user/user/'.$user->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/user/user/'.$user->getRouteKey()), ], 400); } } /** * Remove the user. * * @param Model $user * * @return Response */ public function destroy(UserAdminWebRequest $request, User $user) { try { $t = $user->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('user::user.name')]), 'code' => 202, 'redirect' => trans_url('/admin/user/user/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/user/user/'.$user->getRouteKey()), ], 400); } } }