latest
This commit is contained in:
1 parent
d0834df8df
commit
6dc35134fa
171 files changed
+19241
-49
No files matched your search
@@ -0,0 +1,31 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user