repository = $offer; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Btravel\Card\Repositories\Criteria\OfferResourceCriteria::class); } /** * Display a list of offer. * * @return Response */ public function index(OfferRequest $request) { return $this->repository ->setPresenter(\Btravel\Card\Repositories\Presenter\OfferPresenter::class) ->paginate(); } /** * Display offer. * * @param Request $request * @param Model $offer * * @return Response */ public function show(OfferRequest $request, Offer $offer) { return $offer->setPresenter(\Btravel\Card\Repositories\Presenter\OfferListPresenter::class); ; } /** * Create new offer. * * @param Request $request * * @return Response */ public function store(OfferRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('card::offer.name')]); $code = 204; $status = 'success'; $url = guard_url('card/offer/' . $offer->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('card/offer'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the offer. * * @param Request $request * @param Model $offer * * @return Response */ public function update(OfferRequest $request, Offer $offer) { try { $data = $request->all(); $offer->update($data); $message = trans('messages.success.updated', ['Module' => trans('card::offer.name')]); $code = 204; $status = 'success'; $url = guard_url('card/offer/' . $offer->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('card/offer/' . $offer->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the offer. * * @param Model $offer * * @return Response */ public function destroy(OfferRequest $request, Offer $offer) { try { $offer->delete(); $message = trans('messages.success.deleted', ['Module' => trans('card::offer.name')]); $code = 202; $status = 'success'; $url = guard_url('card/offer/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('card/offer/' . $offer->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }