mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-31 03:16:52 +01:00 
			
		
		
		
	 1900c04b71
			
		
	
	
		1900c04b71
		
			
		
	
	
	
	
		
			
			Co-authored-by: RMartinOscar <40749467+RMartinOscar@users.noreply.github.com> Co-authored-by: Boy132 <Boy132@users.noreply.github.com> Co-authored-by: Lance Pioch <git@lance.sh>
		
			
				
	
	
		
			36 lines
		
	
	
		
			786 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			786 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Services\Users;
 | |
| 
 | |
| use Throwable;
 | |
| use App\Models\User;
 | |
| use Illuminate\Contracts\Hashing\Hasher;
 | |
| use App\Traits\Services\HasUserLevels;
 | |
| 
 | |
| class UserUpdateService
 | |
| {
 | |
|     use HasUserLevels;
 | |
| 
 | |
|     public function __construct(private readonly Hasher $hasher) {}
 | |
| 
 | |
|     /**
 | |
|      * Update the user model instance and return the updated model.
 | |
|      *
 | |
|      * @param  array<array-key, mixed>  $data
 | |
|      *
 | |
|      * @throws Throwable
 | |
|      */
 | |
|     public function handle(User $user, array $data): User
 | |
|     {
 | |
|         if (!empty(array_get($data, 'password'))) {
 | |
|             $data['password'] = $this->hasher->make($data['password']);
 | |
|         } else {
 | |
|             unset($data['password']);
 | |
|         }
 | |
| 
 | |
|         $user->forceFill($data)->saveOrFail();
 | |
| 
 | |
|         return $user->refresh();
 | |
|     }
 | |
| }
 |