瀏覽代碼

Validation for negative values

Hiekki 3 年之前
父節點
當前提交
adba5b1fdb
共有 1 個文件被更改,包括 8 次插入1 次删除
  1. 8 1
      app/Http/Controllers/Api/UserController.php

+ 8 - 1
app/Http/Controllers/Api/UserController.php

@@ -10,6 +10,7 @@ use Illuminate\Contracts\Routing\ResponseFactory;
 use Illuminate\Http\Request;
 use Illuminate\Http\Response;
 use Illuminate\Validation\Rule;
+use Illuminate\Validation\ValidationException;
 
 class UserController extends Controller
 {
@@ -116,7 +117,10 @@ class UserController extends Controller
         
         if($request->credits){
              if ($user->credits - $request->credits >= 99999999) throw ValidationException::withMessages([
-                'credits' => "You cannot remove this amount of credits because you would exceed the minimum credit"
+                'credits' => "You cannot remove this amount of credits because you would exceed the minimum credit limit"
+            ]);
+            elseif($user->credits - $request->credits < 0) throw ValidationException::withMessages([
+                'credits' => "You can't remove this amount of credits because you would exceed the minimum credit limit"
             ]);
             $user->decrement('credits', $request->credits);
          }
@@ -125,6 +129,9 @@ class UserController extends Controller
             if ($user->server_limit - $request->server_limit >= 2147483647) throw ValidationException::withMessages([
                 'server_limit' => "You cannot remove this amount of servers because it would exceed the minimum server."
             ]);
+            elseif($user->server_limit - $request->server_limit < 0) throw ValidationException::withMessages([
+                'server_limit' => "You cannot remove this amount of servers because it would exceed the minimum server."
+            ]);
            $user->decrement('server_limit', $request->server_limit);
         }