私は2つのモデル、製品とフィルタを持っています。Laravel belongsToMany挿入クエリのテーブル順序
製品には多数のフィルタがあり、1つのフィルタには多くの製品が含まれています。多対多の関係。
私が持っている私の製品で:
public function filters() {
return $this->belongsToMany('App\Models\Filter');
}
そして、私のフィルターで:
public function products() {
return $this->belongsToMany('App\Models\Product')->withTimestamps();
}
私は製品を挿入し、このようなフィルタを保存した後にしよう:
$filtersId = $request->filter;
$product->filters()->attach($filtersId);
このエラーが発生しました:
Base table or view not found: 1146 Table 'pontocom-moveis.filter_product' doesn't exist (SQL: insert into `filter_product` (`filter_id`, `product_id`) values (1, 31))
どのように注文をproduct_filterに変更できますか?
私はすでにこの関係のためにテーブルを作成しました。私は、belongsToManyに関係の名前を渡すのを忘れていました。ありがとう。 –