Skip to content

Commit

Permalink
Format response json.
Browse files Browse the repository at this point in the history
  • Loading branch information
furic committed Dec 23, 2020
1 parent 7f35d5c commit 6731cb4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Http/Controllers/RedeemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public function redeem($code)
{
$validator = Validator::make(['code' => $code], ['code' => 'exists:redeem_codes,code']);
if ($validator->fails()) {
return response($validator->errors(), 400); // "The selected code is invalid."
return response(['error' => $validator->errors()->first()], 400); // "The selected code is invalid."
}

$redeemCode = RedeemCode::findByCode($code);

if ($redeemCode->redeemed !== false) {
return response(['code' => ['The selected code has already been redeemed.']], 400);
return response(['error' => 'The selected code has already been redeemed.'], 400);
}

// Check event valid date
Expand All @@ -37,13 +37,13 @@ public function redeem($code)
if ($event->start_at != null) {
$validator = Validator::make($event->toArray(), ['start_at' => 'before:tomorrow']);
if ($validator->fails()) {
return response(['code' => ['The selected code cannot be used yet.']], 400);
return response(['error' => 'The selected code cannot be used yet.'], 400);
}
}
if ($event->end_at != null) {
$validator = Validator::make($event->toArray(), ['end_at' => 'after:yesterday']);
if ($validator->fails()) {
return response(['code' => ['The selected code has expired.']], 400);
return response(['error' => 'The selected code has expired.'], 400);
}
}
}
Expand Down

0 comments on commit 6731cb4

Please sign in to comment.