Luca Parisio 5 ay önce
ebeveyn
işleme
7cb4574e9b
1 değiştirilmiş dosya ile 11 ekleme ve 6 silme
  1. 11 6
      app/Http/Livewire/User.php

+ 11 - 6
app/Http/Livewire/User.php

@@ -52,7 +52,7 @@ class User extends Component
                 'email' => $this->email,
                 'password' => bcrypt($this->password),
                 'level' => $this->level,
-                'enabled' => $this->enabled
+                'enabled' => $this->enabled ? 1 : 0
             ]);
             session()->flash('success','Dato creato');
             $this->resetFields();
@@ -70,8 +70,9 @@ class User extends Component
             } else {
                 $this->name = $user->name;
                 $this->email = $user->email;
-                $this->password = $user->password;
+                $this->oldPassword = $user->password;
                 $this->level = $user->level;
+                $this->enabled = $user->enabled == 1;
                 $this->dataId = $user->id;
                 $this->update = true;
                 $this->add = false;
@@ -83,15 +84,19 @@ class User extends Component
 
     public function update()
     {
-        $this->validate();
+        $this->validate(
+            [
+                'name' => 'required',
+                'email' => 'required',
+            ]
+        );
         try {
-            if ($this->pa)
             \App\Models\User::whereId($this->dataId)->update([
                 'name' => $this->name,
                 'email' => $this->email,
-                'password' => bcrypt($this->password),
+                'password' => $this->password != '' ? bcrypt($this->password) : $this->oldPassword,
                 'level' => $this->level,
-                'enabled' => $this->enabled
+                'enabled' => $this->enabled ? 1 : 0
             ]);
             session()->flash('success','Dato aggiornato');
             $this->resetFields();