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

kannandk's avatar

After Validation hooks in laravel nova

hi , since i am new to laravel , Can any one explain about the After Validation hooks in laravel nova ?,

  1. like where to write the afterValidation() or afterCreationValidation() methods.
  2. in ->updateRules('unique:users,email,{{resourceId}}') what does the resourceId does in the rules.
0 likes
1 reply
tisuchi's avatar

@kannandk

In Laravel Nova, the afterValidation and afterCreationValidation methods are two different lifecycle methods that are called after the validation rules have been applied to the resource.

The afterValidation method is called after the validation rules have been applied to the resource during an update request, while the afterCreationValidation method is called after the validation rules have been applied to the resource during a create request.

You can define these methods in your Nova resource class to perform additional tasks after the validation has been performed.

As for the updateRules method, it is used to specify the validation rules that should be applied when updating a resource. The resourceId parameter represents the ID of the resource being updated. You can use this parameter to exclude the current resource from the unique validation rule.

For example-

$this->updateRules('unique:users,email,{{resourceId}}')

The updateRules method is defining a unique validation rule for the email field in the users' table, but it is excluding the current resource from the rule by using the resourceId parameter. This means that the validation will only fail if there is another user in the users table with the same email address, but a different ID.

1 like

Please or to participate in this conversation.