It looks small problem but I can’t find the best solution.
In Laravel validation, I need to check if the user enters the company email and I’m using ends_with
check. But it is case sensitive
$request->validate([
'username' => [...],
'email' => ['required', 'string', 'email', 'max:50', 'unique:users', 'ends_with:mycompany.com'],
]);
So if the user enters mycompany.com
it will pass the validation but fails when entering MYCOMPANY.COM
or MYCompany.com
2
Answers
If you create a separate request, using
artisan make:request
, you can format the data before it goes through the validation with theprepareForValidation
methodYou can read more on that here
https://laravel.com/docs/9.x/validation#form-request-validation
You can use
PrepareForValidation
method in form request.First make the form request by :
PHP artisan make request
, then add this method to class :