0
votes

I have the following code in a controller method

   $request->validate([
     'facebook'    => 'URL',
     'twitter'     => 'URL',
  ]);

when I provide an invalid data, it fails but returns an improperly formatted message as follows.

I know this can be fixed via Custom validation messages

but for a required field, it shows a proper validation message, What am I missing with URL field

enter image description here

2
I think you need to write url as lower case. So laravel does not transform URL to u_r_l. - Hakan SONMEZ
it not wired in laravel it return with _ in each capital letter example firstName , massage return will be first_name url The field under validation must be a valid URL. as documentation url is all small letter - Jehad Ahmad Jaghoub
@HakanSONMEZ, Yep you are right, I used it wrongly, silly me. - Shobi
To add to what @HakanSONMEZ said: rule names are case sensitive because they are converted to study case (Str::studly()) to locate the method name to call them. Use lowercase url as he mentioned. - Jason Grim

2 Answers

1
votes

validation parameters should typed in lowercase.

$request->validate([
 'facebook'    => 'url',
 'twitter'     => 'url',

]);

0
votes

Yes it was a typo, according to @JasonGrim

rule names are case sensitive because they are converted to study case (Str::studly()) to locate the method name to call them.

So rule names are case sensitive. below one fixed the error

 $request->validate([
        'facebook'    => 'url',
        'twitter'     => 'url',
 ]);