* #23 - wip * #23 - wip * #23 - wip * #23 - wip * #23 - fix * #23 - ecs fix * #23 - fix * #23 - fix * #23 - cr fix
This commit is contained in:
@@ -6,20 +6,24 @@ 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
|
||||
|
28
app/Observers/YearPeriodObserver.php
Normal file
28
app/Observers/YearPeriodObserver.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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()->create([
|
||||
"user_id" => $user->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user