webappAIO/backend/app/Actions/Users/CreateUserAction.php
2026-08-04 11:26:25 +03:00

32 lines
851 B
PHP

<?php
namespace App\Actions\Users;
use App\Models\User;
class CreateUserAction
{
/**
* @param array{name: string, username: string, email: string, password: string, role: string} $data
*/
public function execute(array $data, User $actor): User
{
$user = User::create([
'name' => $data['name'],
'username' => $data['username'],
'email' => $data['email'],
'password' => $data['password'],
'created_by' => $actor->id,
]);
// The DB default (false) applies, but isn't hydrated back onto this
// in-memory instance after insert — set it explicitly for the
// response/event payload built from this same object.
$user->two_factor_enabled = false;
$user->assignRole($data['role']);
return $user;
}
}