<?php

namespace App\Observers;

use App\Models\Notification;
use App\Models\User;

class UserObserver
{
    public function created(User $user): void
    {
        User::role('admin')
            ->where('id', '!=', $user->id)
            ->get(['id'])
            ->each(fn (User $admin) => Notification::create([
                'user_id'        => $admin->id,
                'title'          => 'New user registered',
                'body'           => "{$user->name} just signed up.",
                'url'            => null,
                'is_achievement' => false,
                'achievement_id' => null,
            ]));
    }
}
