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