Laravel validation rule "URL" does not pass empty value Laravel validation rule "URL" does not pass empty value laravel laravel

Laravel validation rule "URL" does not pass empty value


Solve problem use "nullable":

public function rules(){    return [        'field' => 'nullable|url',    ];}


when we submmitting values from js, like through a FormData, the value null could be submitted as string containing 'null', which may pass a nullable rule, cause further type check fail. so be sure to make this value be posted as '', literaly nothing, no a 'null' string


Add sometimes rule to the validation. This means to validate it for a URL when the value is not given or null.

public function rules(){    return [       'field' => 'sometimes|url',    ];}