瀏覽代碼

Merge pull request #159 from ControlPanel-gg/voucher_duplicate_error

500 | Server Error on Duplicate Voucher #133
AVMG 3 年之前
父節點
當前提交
49a895da07
共有 2 個文件被更改,包括 4 次插入4 次删除
  1. 2 2
      app/Http/Controllers/Admin/VoucherController.php
  2. 2 2
      app/Http/Controllers/Api/VoucherController.php

+ 2 - 2
app/Http/Controllers/Admin/VoucherController.php

@@ -45,7 +45,7 @@ class VoucherController extends Controller
     {
         $request->validate([
             'memo'       => 'nullable|string|max:191',
-            'code'       => 'required|string|alpha_dash|max:36|min:4',
+            'code'       => 'required|string|alpha_dash|max:36|min:4|unique:vouchers',
             'uses'       => 'required|numeric|max:2147483647|min:1',
             'credits'    => 'required|numeric|between:0,99999999',
             'expires_at' => 'nullable|multiple_date_format:d-m-Y H:i:s,d-m-Y|after:now|before:10 years',
@@ -91,7 +91,7 @@ class VoucherController extends Controller
     {
         $request->validate([
             'memo'       => 'nullable|string|max:191',
-            'code'       => 'required|string|alpha_dash|max:36|min:4',
+            'code'       => "required|string|alpha_dash|max:36|min:4|unique:vouchers,code,{$voucher->id}",
             'uses'       => 'required|numeric|max:2147483647|min:1',
             'credits'    => 'required|numeric|between:0,99999999',
             'expires_at' => 'nullable|multiple_date_format:d-m-Y H:i:s,d-m-Y|after:now|before:10 years',

+ 2 - 2
app/Http/Controllers/Api/VoucherController.php

@@ -41,7 +41,7 @@ class VoucherController extends Controller
     {
         $request->validate([
             'memo'       => 'nullable|string|max:191',
-            'code'       => 'required|string|alpha_dash|max:36|min:4',
+            'code'       => 'required|string|alpha_dash|max:36|min:4|unique:vouchers',
             'uses'       => 'required|numeric|max:2147483647|min:1',
             'credits'    => 'required|numeric|between:0,99999999',
             'expires_at' => 'nullable|multiple_date_format:d-m-Y H:i:s,d-m-Y|after:now|before:10 years'
@@ -85,7 +85,7 @@ class VoucherController extends Controller
 
         $request->validate([
             'memo'       => 'nullable|string|max:191',
-            'code'       => 'required|string|alpha_dash|max:36|min:4',
+            'code'       => "required|string|alpha_dash|max:36|min:4|unique:vouchers,code,{$voucher->id}",
             'uses'       => 'required|numeric|max:2147483647|min:1',
             'credits'    => 'required|numeric|between:0,99999999',
             'expires_at' => 'nullable|multiple_date_format:d-m-Y H:i:s,d-m-Y|after:now|before:10 years'