public function postRedeem(Request $request) { $api = new API(); $voucher = Voucher::findOrFail($request->code); if (!VoucherLog::redeemed($voucher->id)->exists()) { $mail = ['title' => trans('voucher.mail.title', ['code' => $request->code]), 'message' => trans('voucher.mail.message', ['name' => $voucher->item_name, 'count' => $voucher->item_count]), 'money' => 0, 'item' => ['id' => $voucher->item_id, 'pos' => 0, 'count' => $voucher->item_count, 'max_count' => $voucher->item_count, 'data' => $voucher->item_octets, 'proctype' => $voucher->item_proc_type, 'expire_date' => 0, 'guid1' => 0, 'guid2' => 0, 'mask' => $voucher->item_mask]]; $api->sendMail(Auth::user()->characterId(), $mail['title'], $mail['message'], $mail['item'], $mail['money']); VoucherLog::create(['voucher_id' => $voucher->id, 'user_id' => Auth::user()->ID]); flash()->success(trans('voucher.successfully_redeemed')); } else { flash()->error(trans('voucher.already_redeemed')); } return redirect()->back(); }
public function redeem(Request $request) { $this->validate($request, ['number' => 'required|alpha_num|exists:vouchers,number,redeemed_by,NULL']); // Redeem voucher $id (number) for the posting User. $voucher = Voucher::whereNumber($request['number'])->first(); // Grab user and add to their balance. $user = Auth::User(); // Check to verify that this isn't a user redeeming their own vouchers. if ($voucher->user_id == $user->id) { flash()->error('Unable to redeem voucher issued to yourself.'); return redirect()->route('settings.billing'); } $user->credit += $voucher->amount; $user->save(); // Mark the voucher as claimed. $voucher->redeemed_by = $user->id; $voucher->redeemed_at = Carbon::now(); $voucher->save(); // Return to billing page wish a success message flash()->success('Successfully redeemed voucher.'); return redirect()->route('settings.billing'); }
/** * Remove the specified resource from storage. * * @param Request $request * @param Voucher $voucher * @return \Illuminate\Http\Response */ public function destroy(Request $request, Voucher $voucher) { if ($request->ajax()) { $voucher->delete(); } }