Home > front end >  I can't verify object after json_decode()
I can't verify object after json_decode()

Time:12-26

 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',

    ]);
  • Related