You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
569 B
29 lines
569 B
<?php
|
|
|
|
namespace App\Domains\Identity\Queries;
|
|
|
|
use App\Domains\Identity\Models\User;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class GetAuthenticatedUserContext
|
|
{
|
|
private ?array $cache = null;
|
|
|
|
public function fetch(): ?User
|
|
{
|
|
if ($this->cache !== null) {
|
|
return $this->cache['user'];
|
|
}
|
|
|
|
$user = Auth::user();
|
|
$user?->loadMissing(['avatar', 'profile']);
|
|
$this->cache['user'] = $user;
|
|
|
|
return $this->cache['user'];
|
|
}
|
|
|
|
public function refresh(): void
|
|
{
|
|
$this->cache = null;
|
|
}
|
|
}
|
|
|