repository = $offer; parent::__construct(); } /** * Display a list of offer. * * @return Response */ public function index(OfferAdminWebRequest $request) { if ($request->wantsJson()) { $offers = $this->repository->setPresenter('\\Guru\\Offer\\Repositories\\Presenter\\OfferListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); return response()->json($offers, 200); } $this ->theme->prependTitle(trans('offer::offer.names').' :: '); return $this->theme->of('offer::admin.offer.index')->render(); } /** * Display offer. * * @param Request $request * @param Model $offer * * @return Response */ public function show(OfferAdminWebRequest $request, Offer $offer) { if (!$offer->exists) { return response()->view('offer::admin.offer.new', compact('offer')); } Form::populate($offer); return response()->view('offer::admin.offer.show', compact('offer')); } /** * Show the form for creating a new offer. * * @param Request $request * * @return Response */ public function create(OfferAdminWebRequest $request) { $offer = $this->repository->newInstance([]); Form::populate($offer); return response()->view('offer::admin.offer.create', compact('offer')); } /** * Create new offer. * * @param Request $request * * @return Response */ public function store(OfferAdminWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $offer = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('offer::offer.name')]), 'code' => 204, 'redirect' => trans_url('/admin/offer/offer/'.$offer->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show offer for editing. * * @param Request $request * @param Model $offer * * @return Response */ public function edit(OfferAdminWebRequest $request, Offer $offer) { Form::populate($offer); return response()->view('offer::admin.offer.edit', compact('offer')); } /** * Update the offer. * * @param Request $request * @param Model $offer * * @return Response */ public function update(OfferAdminWebRequest $request, Offer $offer) { try { $attributes = $request->all(); $offer->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('offer::offer.name')]), 'code' => 204, 'redirect' => trans_url('/admin/offer/offer/'.$offer->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/offer/offer/'.$offer->getRouteKey()), ], 400); } } /** * Remove the offer. * * @param Model $offer * * @return Response */ public function destroy(OfferAdminWebRequest $request, Offer $offer) { try { $t = $offer->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('offer::offer.name')]), 'code' => 202, 'redirect' => trans_url('/admin/offer/offer/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/offer/offer/'.$offer->getRouteKey()), ], 400); } } }