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