I need to update HasMany
relation with set of id's.
Faq model.
class Faq extends Model
{
public function products(){
return $this->belongsToMany(Product::class, 'faq_products');
}
}
I have Product
model and pivot table 'faq_products' for HasMany
relation.
faq_products table
Schema::create('faq_products', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('faq_id')->unsigned()->nullable();
$table->foreign('faq_id')->references('id')->on('faqs')->onDelete('cascade');
$table->integer('product_id')->unsigned()->nullable();
$table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
$table->timestamps();
});
And I'm getting an array of product ids from request related to faq but not sure how to update the relationship.
array
$product_ids = [4, 3, 2];