public static function refillOnline($uid, $data) { DB::transaction(function () use($uid, $data) { $temp = ['validity' => 1, 'validity_unit' => 'Days', 'count' => 1]; $data = array_merge($data, $temp); if (!($pins = self::generate($data))) { throw new Exception('Refill Failed. Phase:1'); } $pin = current($pins); if (!self::now($pin, $uid, 'online')) { throw new Exception("Refill Failed. Phase:2"); } if (!Refillcoupons::where('pin', $pin)->update(['user_id' => $uid])) { throw new Exception('Refill Failed. Phase:3'); } }); }