blog:{
postTitle: '',
}
this is in JS
let data = new FormData();
const blog = JSON.stringify(this.blog);
data.append('blog',blog);
Laravel
$blog = json_decode(request('blog'));
$blog->validate([
'blog.postTitle' => 'required'
]);
I have tried to: after I decode it I have tried to:
return $request['blog']
and it works.
Error for validation I get is:
Call to undefined method stdClass::validate()
CodePudding user response:
I am sending blog object(without JSON.stingify()
), and now validation works.
await this.setCreatePost({data, blog})
request()->validate([
'blog.postTitle' => 'required|max:100|string',
'blog.sectionTitles.*.title' => 'required|string|max:100',
'blog.sectionTitles.*.belongsTo' => 'required|integer|max:1',
'blog.textareas.*.text' => 'required|string|max:500',
'blog.textareas.*.belongsTo' => 'required|integer|max:1',
]);