Hi, i have an eloquent model with a json field which is called "sections_details", i have created a request that extends the form request and i am using the rules function llike this:
public function rules()
{
return [
....
'sections_details'=> 'required|json'
];
}
When i try to store an instance of this model using postman the validation fails and it tells me that the data must be a valid json string. I send this using postman
"sections_details":{
"section": "1",
"hours": "3 a 9"
}
I know i can use the character \ before the quotes in postman and send it correctly but i do not want that. I have thought of using the prepareForValidation() method but i am not sure if that's correct
*/
protected function prepareForValidation()
{
$this->merge([
'sections_details' => json_encode($this->sections_details)
]);
}
Is this a good way of solve it? Is there a better way? Thanks a lot;