Form validation

model-form uses Laravel's validation rules to verify the data submitted by the form:


// Complex validation rules can be implemented in the callback
$form->text('title')->rules(function ($form) {

    // If it is not an edit state, add field unique verification
    if (!$id = $form->model()->id) {
        return 'unique:users,email_address';


You can also customize the error message for the validation rule:

$form->text('code')->rules('required|regex:/^\d+$/|min:10', [
    'regex' => 'code must be numbers',
    'min'   => 'code can not be less than 10 characters',

If you want to allow the field to be empty, first in the database table to face the field set to NULL, and then


Please refer to the more rules Validation.

Create page rules

Only effective when creating a form submission


Update page rules

Only effective when the update form is submitted


Database unique check

A more common scenario is to submit a form to check if the data already exists. You can use the following method:

     ->creationRules(['required', "unique:user_table"])
     ->updateRules(['required', "unique:user_table,username,{{id}}"]);