#48 - user avatars using ui-avatars.com

This commit is contained in:
Adrian Hopek
2022-03-04 09:25:28 +01:00
parent 697f3395bd
commit ecae457c1f
21 changed files with 192 additions and 266 deletions

View File

@@ -4,37 +4,19 @@ declare(strict_types=1);
namespace Toby\Eloquent\Observers;
use Illuminate\Support\Facades\Storage;
use Toby\Eloquent\Helpers\UserAvatarGenerator;
use Toby\Eloquent\Helpers\YearPeriodRetriever;
use Toby\Eloquent\Models\User;
class UserObserver
{
public function __construct(
protected UserAvatarGenerator $generator,
protected YearPeriodRetriever $yearPeriodRetriever,
) {}
public function created(User $user): void
{
$user->saveAvatar($this->generator->generateFor($user));
$user->vacationLimits()->create([
"year_period_id" => $this->yearPeriodRetriever->current()->id,
]);
}
public function updating(User $user): void
{
if ($user->isDirty(["first_name", "last_name"])) {
Storage::delete($user->avatar);
$user->avatar = $this->generator->generateFor($user);
}
}
public function forceDeleted(User $user): void
{
Storage::delete($user->avatar);
}
}