Explorar el Código

User server gets suspended / unsuspended if an user accounts get suspended / unsuspended

Johannes hace 3 años
padre
commit
b1ca573dd1
Se han modificado 1 ficheros con 10 adiciones y 0 borrados
  1. 10 0
      app/Models/User.php

+ 10 - 0
app/Models/User.php

@@ -177,6 +177,10 @@ class User extends Authenticatable implements MustVerifyEmail
      */
      */
     public function suspend()
     public function suspend()
     {
     {
+        foreach ($this->servers as $server){
+            $server->suspend();
+        }
+
         $this->update([
         $this->update([
             'suspended' => true
             'suspended' => true
         ]);
         ]);
@@ -189,6 +193,12 @@ class User extends Authenticatable implements MustVerifyEmail
      */
      */
     public function unSuspend()
     public function unSuspend()
     {
     {
+        foreach ($this->servers as $server){
+          if ($this->credits >= $server->product->getHourlyPrice()) {
+            $server->unSuspend();
+        }
+        }
+
         $this->update([
         $this->update([
             'suspended' => false
             'suspended' => false
         ]);
         ]);