Skip to content

Commit

Permalink
Create beneficiary - fix staff (#97)
Browse files Browse the repository at this point in the history
* Create beneficiary - fix staff

* refactor

---------

Co-authored-by: Andrei Ioniță <[email protected]>
  • Loading branch information
alexPopaCode4 and andreiio authored Aug 1, 2024
1 parent 0b3497c commit 761f67e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/Models/Beneficiary.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,17 @@ class Beneficiary extends Model
protected static function booted()
{
static::created(function (Beneficiary $beneficiary) {
if (auth()->user()?->can_be_case_manager) {
$beneficiary->team()->create([
'user_id' => auth()->user()->id,
'roles' => [Role::MANGER],
]);
if (auth()->guest()) {
return;
}

$user = auth()->user();
$beneficiary->team()->create([
'user_id' => $user->id,
'roles' => $user->can_be_case_manager
? [Role::MANGER]
: $user->roles,
]);
});
}

Expand Down

0 comments on commit 761f67e

Please sign in to comment.