|
|
@@ -20,12 +20,12 @@ public function authUser(): ?User
|
|
|
|
|
|
public function getAll(): Collection
|
|
|
{
|
|
|
- return User::with('state')->orderBy('name')->get();
|
|
|
+ return User::with(['state', 'units'])->orderBy('name')->get();
|
|
|
}
|
|
|
|
|
|
public function findById(int $id): ?User
|
|
|
{
|
|
|
- return User::with('state')->find($id);
|
|
|
+ return User::with(['state', 'units'])->find($id);
|
|
|
}
|
|
|
|
|
|
public function create(array $data): User
|
|
|
@@ -54,10 +54,15 @@ public function update(int $id, array $data): ?User
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ $unitId = $data['unit_id'] ?? null;
|
|
|
unset($data['unit_id']);
|
|
|
+
|
|
|
$data = $this->handleAvatar($data, $model->avatar_url);
|
|
|
$model->update($data);
|
|
|
- return $model->fresh(['state']);
|
|
|
+
|
|
|
+ $model->units()->sync($unitId ? [$unitId] : []);
|
|
|
+
|
|
|
+ return $model->fresh(['state', 'units']);
|
|
|
}
|
|
|
|
|
|
public function delete(int $id): bool
|