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