1
I would like to validate a field and make that field not mandatory.
I know that for him to be obligatory I must wear required
but I didn’t use it, since I only wanted to validate an email if it was added by the user, so I used validation 'email'
.
But it turns out that even I not using the required
it by default forces the user to put a value in the field thus leaving the required field. To make it simpler I will put a code below:
namespace App\Http\Requests\Dashboard;
use Illuminate\Foundation\Http\FormRequest;
class FormEditarUsuario extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
// dd('ok');
return [
'email' => 'email'
];
}
public function messages()
{
return [
'email.email' => 'Campo email inválido'
];
}
}
Summarizing wanted to validate, but in case the user does not put any value in the field it does not return a validation error!
NOTE: I have tried using min:0
obg cara pior q euli the documentation, but as I was programming at dawn and I was no longer reading thing with thing I think q passed beaten, but thanks ai helped a lot hug brother!
– Schielke