コード例 #1
0
ファイル: Coupon.php プロジェクト: emadmrz/Hawk
 /**
  * Created By Dara on 30/10/2015
  * check if the coupon is valid or not by expired_at
  */
 public function getValidAttribute()
 {
     $coupon = CouponGallery::where('id', $this->attributes['coupon_gallery_id'])->firstOrFail();
     $expired_at = $coupon->expired_at;
     if ($expired_at >= Carbon::now()) {
         return true;
     } else {
         return false;
     }
 }
コード例 #2
0
ファイル: CouponController.php プロジェクト: emadmrz/Hawk
 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()];
 }