Changeset View
Changeset View
Standalone View
Standalone View
src/app/Observers/UserObserver.php
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | public function created(User $user) | ||||
// Create user record in LDAP, then check if the account is created in IMAP | // Create user record in LDAP, then check if the account is created in IMAP | ||||
$chain = [ | $chain = [ | ||||
new \App\Jobs\UserVerify($user), | new \App\Jobs\UserVerify($user), | ||||
]; | ]; | ||||
\App\Jobs\UserCreate::withChain($chain)->dispatch($user); | \App\Jobs\UserCreate::withChain($chain)->dispatch($user); | ||||
} | } | ||||
public function deleted(User $user) | |||||
{ | |||||
// | |||||
} | |||||
/** | /** | ||||
* Handle the "deleting" event. | * Handle the "deleting" event. | ||||
* | * | ||||
* @param User $user The user that is being deleted. | * @param User $user The user that is being deleted. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function deleting(User $user) | public function deleting(User $user) | ||||
{ | { | ||||
// TODO \App\Jobs\UserDelete::dispatch($user); | // Entitlements do not have referential integrity on the entitled object, so this is our | ||||
// way of doing an onDelete('cascade') without the foreign key. | |||||
$entitlements = \App\Entitlement::where('entitleable_id', $user->id) | |||||
->where('entitleable_type', \App\User::class)->get(); | |||||
foreach ($entitlements as $entitlement) { | |||||
$entitlement->delete(); | |||||
} | |||||
machniak: You don't need the loop, you can just cal ->delete() instead of ->get(). | |||||
\App\Jobs\UserDelete::dispatch($user->id); | |||||
} | } | ||||
/** | /** | ||||
* Handle the "retrieving" event. | * Handle the "retrieving" event. | ||||
* | * | ||||
* @param User $user The user that is being retrieved. | * @param User $user The user that is being retrieved. | ||||
* | * | ||||
* @todo This is useful for audit. | * @todo This is useful for audit. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function retrieving(User $user) | public function retrieving(User $user) | ||||
{ | { | ||||
// TODO \App\Jobs\UserRead::dispatch($user); | // TODO \App\Jobs\UserRead::dispatch($user); | ||||
} | } | ||||
/** | /** | ||||
* Handle the "updating" event. | * Handle the "updating" event. | ||||
* | * | ||||
* @param User $user The user that is being updated. | * @param User $user The user that is being updated. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function updating(User $user) | public function updating(User $user) | ||||
{ | { | ||||
\App\Jobs\UserUpdate::dispatch($user); | \App\Jobs\UserUpdate::dispatch($user); | ||||
} | } | ||||
} | } |
You don't need the loop, you can just cal ->delete() instead of ->get().