Is it possible to create this function in CustomerResource.php?
Hello everyone, good morning, it is possible at CostumerResource.php
create a function to check if the customer is already registered with the same cnpj, stop the creation function and show the notification to him, please help me how should I do this.
would it be like this?
public static function save()
{
$cnpj = request()->input('cnpj');
// Checks if there is already a Customer with the same CNPJ
if (Customer::where('cnpj', $cnpj)->exists()) {
// Returns an error message indicating that the CNPJ already exists
Notification::make()
->title('')
->body('')
->warning()
->send()
}
// If it does not exist, continue with the save operation
return parent::save();
}
2 Replies
why don't you just add unique validation to that input component
TextInput::make('cnpj')->unique(ignoreRecord: true)