middleware(function ($request, $next) { $this->form = OfferForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('bixo.opportunity.modules'), 'opportunity', guard_url('opportunity')); return $next($request); }); } /** * Display a list of offer. * * @return Response */ public function index(OfferResourceRequest $request) { $request = $request->all(); $page = OfferActions::run('paginate', $request); $data = new OffersCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('opportunity::offer.names')) ->view('opportunity::offer.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display offer. * * @param Request $request * @param Model $offer * * @return Response */ public function show(OfferResourceRequest $request, Offer $model) { $form = $this->form; $modules = $this->modules; $data = new OfferResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('opportunity::offer.name')) ->data(compact('data', 'form', 'modules')) ->view('opportunity::offer.show') ->output(); } /** * Show the form for creating a new offer. * * @param Request $request * * @return Response */ public function create(OfferResourceRequest $request, Offer $model) { $form = $this->form; $modules = $this->modules; $data = new OfferResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('opportunity::offer.name')) ->view('opportunity::offer.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new offer. * * @param Request $request * * @return Response */ public function store(OfferResourceRequest $request, Offer $model) { try { $request = $request->all(); $model = OfferAction::run('store', $model, $request); $data = new OfferResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('opportunity::offer.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('opportunity/offer/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/opportunity/offer')) ->redirect(); } } /** * Show offer for editing. * * @param Request $request * @param Model $offer * * @return Response */ public function edit(OfferResourceRequest $request, Offer $model) { $form = $this->form; $modules = $this->modules; $data = new OfferResource($model); // return view('opportunity::offer.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('opportunity::offer.name')) ->view('opportunity::offer.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the offer. * * @param Request $request * @param Model $offer * * @return Response */ public function update(OfferResourceRequest $request, Offer $model) { try { $request = $request->all(); $model = OfferAction::run('update', $model, $request); $data = new OfferResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('opportunity::offer.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('opportunity/offer/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('opportunity/offer/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the offer. * * @param Model $offer * * @return Response */ public function destroy(OfferResourceRequest $request, Offer $model) { try { $request = $request->all(); $model = OfferAction::run('destroy', $model, $request); $data = new OfferResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('opportunity::offer.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('opportunity/offer/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('opportunity/offer/' . $model->getRouteKey())) ->redirect(); } } }