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