Answer the question
In order to leave comments, you need to log in
Save Many to Many Laravel 5.3?
There is a Pivot table, where the product id and tag id.
controller:
$tagsNames = ['1', '2', '3'];
$product->productTags->saveMany([
new Tag(['tag_id' => '1']),
new Tag(['tag_id' => '2']),
new Tag(['tag_id' => '3']),
]);
public function productTags()
{
return $this->belongsToMany('App\Tag', 'product_tags');
}
// тоже самое только наоборот в модели Tag
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question