repository = $user; $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->pushCriteria(new \Provider\Package\Repositories\Criteria\UserUserCriteria()); parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(UserRequest $request) { $users = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('package::user.names')); return $this->theme->of('package::user.user.index', compact('users'))->render(); } /** * Display the specified resource. * * @param Request $request * @param User $user * * @return Response */ public function show(UserRequest $request, User $user) { Form::populate($user); return $this->theme->of('package::user.user.show', compact('user'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(UserRequest $request) { $user = $this->repository->newInstance([]); Form::populate($user); $this->theme->prependTitle(trans('package::user.names')); return $this->theme->of('package::user.user.create', compact('user'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(UserRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $user = $this->repository->create($attributes); return redirect(trans_url('/user/package/user')) -> with('message', trans('messages.success.created', ['Module' => trans('package::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(UserRequest $request, User $user) { Form::populate($user); $this->theme->prependTitle(trans('package::user.names')); return $this->theme->of('package::user.user.edit', compact('user'))->render(); } /** * Update the specified resource. * * @param Request $request * @param User $user * * @return Response */ public function update(UserRequest $request, User $user) { try { $this->repository->update($request->all(), $user->getRouteKey()); return redirect(trans_url('/user/package/user')) ->with('message', trans('messages.success.updated', ['Module' => trans('package::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(UserRequest $request, User $user) { try { $this->repository->delete($user->getRouteKey()); return redirect(trans_url('/user/package/user')) ->with('message', trans('messages.success.deleted', ['Module' => trans('package::user.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }