This commit is contained in:
Adrian Hopek
2022-01-24 10:19:26 +01:00
parent b4c6cfe612
commit 75889a16e6
12 changed files with 223 additions and 24 deletions

View File

@@ -6,20 +6,22 @@ namespace Toby\Observers;
use Illuminate\Support\Facades\Storage;
use Toby\Helpers\UserAvatarGenerator;
use Toby\Helpers\YearPeriodRetriever;
use Toby\Models\User;
class UserObserver
{
public function __construct(
protected UserAvatarGenerator $generator,
protected YearPeriodRetriever $yearPeriodRetriever,
) {
}
public function created(User $user): void
{
$user->avatar = $this->generator->generateFor($user);
$user->saveAvatar($this->generator->generateFor($user));
$user->save();
$user->vacationLimits()->create(["year_period_id" => $this->yearPeriodRetriever->current()->id]);
}
public function updating(User $user): void

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Toby\Observers;
use Toby\Helpers\UserAvatarGenerator;
use Toby\Models\User;
use Toby\Models\YearPeriod;
class YearPeriodObserver
{
public function __construct(
protected UserAvatarGenerator $generator,
) {
}
public function created(YearPeriod $yearPeriod): void
{
$users = User::all();
foreach ($users as $user) {
$yearPeriod->vacationLimits()->updateOrCreate(["user_id" => $user->id]);
}
}
}