Skip to content

Commit 6114513

Browse files
committed
Adding method to create a role without triggering the event
1 parent 8ea5327 commit 6114513

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

Repositories/Sentinel/SentinelUserRepository.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function all()
4242
public function create(array $data)
4343
{
4444
$user = $this->user->create((array) $data);
45-
45+
4646
event(new UserHasRegistered($user));
4747

4848
return $user;
@@ -69,6 +69,28 @@ public function createWithRoles($data, $roles, $activated = false)
6969
}
7070
}
7171

72+
/**
73+
* Create a user and assign roles to it
74+
* But don't fire the user created event
75+
* @param array $data
76+
* @param array $roles
77+
* @param bool $activated
78+
*/
79+
public function createWithRolesFromCli($data, $roles, $activated = false)
80+
{
81+
$this->hashPassword($data);
82+
$user = $this->user->create((array) $data);
83+
84+
if (!empty($roles)) {
85+
$user->roles()->attach($roles);
86+
}
87+
88+
if ($activated) {
89+
$activation = Activation::create($user);
90+
Activation::complete($user, $activation->code);
91+
}
92+
}
93+
7294
/**
7395
* Find a user by its ID
7496
* @param $id

Repositories/UserRepository.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ public function create(array $data);
2727
*/
2828
public function createWithRoles($data, $roles, $activated = false);
2929

30+
/**
31+
* Create a user and assign roles to it
32+
* But don't fire the user created event
33+
* @param array $data
34+
* @param array $roles
35+
* @param bool $activated
36+
*/
37+
public function createWithRolesFromCli($data, $roles, $activated = false);
38+
3039
/**
3140
* Find a user by its ID
3241
* @param $id

0 commit comments

Comments
 (0)