File "AuthenticatedUserReference.php"

Full Path: /var/www/html/back/vendor/spatie/laravel-data/src/Support/Validation/References/AuthenticatedUserReference.php
File size: 671 bytes
MIME-type: text/x-php
Charset: utf-8

<?php

namespace Spatie\LaravelData\Support\Validation\References;

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\Auth;

class AuthenticatedUserReference implements ExternalReference
{
    public function __construct(
        public ?string $property = null,
        public ?string $guard = null,
    ) {
    }

    public function getValue(): ?Authenticatable
    {
        $user = Auth::guard($this->guard)->user();

        if (! $user instanceof Authenticatable) {
            return null;
        }

        if ($this->property === null) {
            return $user;
        }

        return data_get($user, $this->property);
    }
}