Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

abkrim's avatar
Level 13

Nova field validate using data of other field

Hi.

I have a text field (email) that needs to be validated with the value of a BelongsTo relationship

Text::make(__('Mailbox'), 'username')
    ->sortable()
    ->rules('required', 'email', 'max:254')
    ->creationRules('unique:mailboxes,username')
    ->readonly(function() {
        return $this->resource->id ? true : false;
    }),
...
BelongsTo::make('Domain')->hideFromDetail()->hideWhenUpdating(),

I need that user validate a mailbox with a valid email of same domain selected in BelongsTo.

Is possible ?

0 likes
2 replies
abkrim's avatar
Level 13

Well.

I read this. But I don't understand how to I send to rule data for verify if $attribute has a $value and this $value has part of other attribute named "domain"

According documentation object rules

 public function passes($attribute, $value)
    {
        return strtoupper($value) === $value;
    }

On your reply I don't see a way for pass data to rule. Data (And my question) is field on relationship BelongTo, named "domain"

Best regards

1 like

Please or to participate in this conversation.