public function edit(Offer $offer) { //check if the offer is valid or not if (!$offer->valid()) { Flash::error(trans('messages.offerExpired')); return redirect(route('profile.management.addon.offer')); } $user = Auth::user(); $specialOffers = $offer->coupon_gallery()->valid()->lists('title', 'id'); $coupons = $offer->coupons()->get(); return view('store.offer.edit', compact('user', 'offer', 'specialOffers', 'coupons'))->with(['title' => 'ویرایش پینهاد ویژه']); }
public function create(Request $request, Offer $offer) { if ($request->user()->cannot('edit-offer', [$offer])) { abort(403); } $this->validate($request, ['offer' => 'required|integer', 'num' => 'required|integer|min:1', 'title' => 'required|min:3', 'description' => 'required|min:3', 'real_amount' => 'required|integer', 'pay_amount' => 'required|integer']); $user = Auth::user(); $input = $request->all(); //check if the service is valid or not $service = CouponGallery::where('id', $input['offer'])->firstOrFail(); if ($service->expired_at < Carbon::now()) { abort(403); } $coupon = $user->coupons()->create(['offer_id' => $offer->id, 'coupon_gallery_id' => $input['offer'], 'title' => $input['title'], 'description' => $input['description'], 'real_amount' => $input['real_amount'], 'pay_amount' => $input['pay_amount'], 'num' => $input['num']]); return ['hasCallback' => '1', 'callback' => 'service_coupon', 'hasMsg' => 0, 'msg' => '', 'returns' => $offer->coupons()->with('coupon_gallery')->get()]; }