Files
lucent-laravel/src/Account/UserProfile.php
T
2023-10-02 23:10:49 +03:00

40 lines
794 B
PHP

<?php
namespace Lucent\Account;
readonly class UserProfile
{
function __construct(
public string $id,
public string $name,
public string $email,
public Role $role,
)
{
}
public static function fromUser(User $user): UserProfile
{
return new UserProfile(
$user->id,
$user->name,
$user->email,
$user->role,
);
}
public static function fromArray(array $data): ?UserProfile
{
if (empty($data)) {
return null;
}
return new UserProfile(
id: data_get($data, "id"),
name: data_get($data, "name"),
email: data_get($data, "email"),
role: data_get($data, "role"),
);
}
}