i have this error when I try to send an array to my database table. i have this on my update method
$post = Post::findOrFail($id);
$post->PostTitle = $request->PostTitle;
$post->post = $request->post;
$tags = new Tag;
foreach ($request->tags as $tags) {
$tag = Tag::create(['tag' => $tags]);
if ($tag->save()) {
$post->tags()->sync($tag->id);
}
}
this is my html form
<div class="post-panel-3">
<div class="form-group">
<label for="postTags">Etiquetas: </label>
<input type="text" name="tags[]" class="form-control" placeholder="Etiquetas" value="<?php if(isset($post->tags)){ foreach($post->tags as $tag); echo $tag->tag;} ?>" id="tagBox2">
I have ManyToMany relationship model, all run fine in create method but no on update. I think i miss something but not finded yet.
taggged, nottags. And the field is most likely malformed from the way you're creating it in your form.12342236if your post has the tags 1, 2, 3, 4, 22, and 36. You should probably put the tags field inside the foreach instead.syncwhich means each time through the loop, you are going to erase all past tags you just saved for that post. You probably want to useattachinstead.