| @@ 41-57 (lines=17) @@ | ||
| 38 | * @param array $pivot_columns |
|
| 39 | * @return self |
|
| 40 | */ |
|
| 41 | public function addUsers(array $users = [], array $pivot_columns = []) : self |
|
| 42 | { |
|
| 43 | $keyed = collect($users) |
|
| 44 | ->mapWithKeys(function ($user) use ($pivot_columns) { |
|
| 45 | return [ |
|
| 46 | is_a($user, user_model()) ? $user->id : $user => $pivot_columns, |
|
| 47 | ]; |
|
| 48 | })->toArray(); |
|
| 49 | ||
| 50 | $this->users()->syncWithoutDetaching($keyed); |
|
| 51 | ||
| 52 | $this->load('users'); |
|
| 53 | ||
| 54 | $this->refresh('users'); |
|
| 55 | ||
| 56 | return $this; |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * Remove the given user from the current Project |
|
| @@ 76-90 (lines=15) @@ | ||
| 73 | * @param array $users |
|
| 74 | * @return self |
|
| 75 | */ |
|
| 76 | public function removeUsers(array $users = []) : self |
|
| 77 | { |
|
| 78 | $keyed = collect($users) |
|
| 79 | ->map(function ($user) { |
|
| 80 | return is_a($user, user_model()) ? $user->id : $user; |
|
| 81 | })->toArray(); |
|
| 82 | ||
| 83 | $this->users()->detach($keyed); |
|
| 84 | ||
| 85 | $this->load('users'); |
|
| 86 | ||
| 87 | $this->refresh('users'); |
|
| 88 | ||
| 89 | return $this; |
|
| 90 | } |
|
| 91 | ||
| 92 | /** |
|
| 93 | * Check if the given user is on the current Project |
|