middleware('web'); $this->middleware('auth:web'); $this->setupTheme(config('theme.themes.user.theme'), config('theme.themes.user.layout')); $this->repository = $user; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(UserUserWebRequest $request) { $this->repository->pushCriteria(new \Sample\User\Repositories\Criteria\UserUserCriteria()); $users = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('user::user.names').' :: '); return $this->theme->of('user::user.user.index', compact('users'))->render(); } /** * Display the specified resource. * * @param Request $request * @param User $user * * @return Response */ public function show(UserUserWebRequest $request, User $user) { Form::populate($user); return $this->theme->of('user::user.user.show', compact('user'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(UserUserWebRequest $request) { $user = $this->repository->newInstance([]); Form::populate($user); return $this->theme->of('user::user.user.create', compact('user'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(UserUserWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $user = $this->repository->create($attributes); return redirect(trans_url('/user/user/user')) -> with('message', trans('messages.success.created', ['Module' => trans('user::user.name')])) -> with('code', 201); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param User $user * * @return Response */ public function edit(UserUserWebRequest $request, User $user) { Form::populate($user); return $this->theme->of('user::user.user.edit', compact('user'))->render(); } /** * Update the specified resource. * * @param Request $request * @param User $user * * @return Response */ public function update(UserUserWebRequest $request, User $user) { try { $this->repository->update($request->all(), $user->getRouteKey()); return redirect(trans_url('/user/user/user')) ->with('message', trans('messages.success.updated', ['Module' => trans('user::user.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(UserUserWebRequest $request, User $user) { try { $this->repository->delete($user->getRouteKey()); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('user::user.name')]), 'code' => 202, 'redirect' => trans_url('/user/user/user/0'), ], 202); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }