Вставка данных в Pivot-таблицу

class Product extends Model
{
    use HasFactory;

    public function elements()
    {
        return $this->belongsToMany(Element::class);
    }

}

class Element extends Model
{
    use HasFactory;

    public function products()
    {
        return $this->belongsToMany(Product::class);
    }

}

Связующая таблица называется "product_element".

class MainController extends Controller
{

    public function index()
    {
        $product = Product::find(3);
        $product->elements()->attach([19, 20, 12]);

        return view('base', ['r' => Element::get(['id', 'name'])]);
    }
}

Выдает ошибку: "SQLSTATE[42S02]: Base table or view not found: 1146 Table 'element_product' doesn't exist (SQL: insert into element_product (element_id, product_id) values (19, 3), (20, 3), (12, 3))"


Ответы (0 шт):