Laravel FromRequest the given value must be true or false

i am sending boolean type date from angular frontend to laravel backend and i am using FormRequest for data validation.
here is the data i send from angular:

{'full_name' : searchTerm,'is_search_friend':true}

FormRequest
  'full_name' => 'required|string|min:1|max:50',
  'is_search_friend' => 'required|boolean'

i get this error :

is_search_friend: [” is search friend must be true or false”]

meanwhile i am sending a boolean type data ‘is-search_friend’

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

If you are sending the data {'full_name' : searchTerm,'is_search_friend':true} as multipart/formdata then the the request must need to be like

{'full_name' : searchTerm,'is_search_friend':1} //1 for true 0 for false

of if you pass value as RAW JSON data then the request will be
{
"full_name" : "searchTerm",
"is_search_friend":true
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x