RelationManager belongsToMany withPivot(['id']) returns Column 'id' in order clause is ambiguous

When attaching an Product item to my Warehouse model which is a manyToMany relationship. I'm getting an SQL error (see below)
the order by should contain the pivot table name ....

i need the "id" because my attachments can be duplicated. I also already have configured: $table->allowDuplicates()

this is my migration:

Schema::create('product_warehouse', function (Blueprint $table) {

            $table->id();
            $table->foreignId('product_id');
            $table->foreignId('warehouse_id');
            $table->string('quantity');
            $table->text('location_info');
            $table->timestamps();
        });


Product Model:
public function warehouses()
    {
        return $this->belongsToMany(Warehouse::class)->withPivot(['id', 'quantity', 'location_info']);
    }

Warehouse Model:

public function products(): BelongsToMany
    {
        return $this->belongsToMany(Product::class)->withPivot(['id', 'quantity', 'location_info']);
    }


SELECT
  `product_warehouse`.`warehouse_id` AS `pivot_warehouse_id`,
  `product_warehouse`.`product_id` AS `pivot_product_id`,
  `product_warehouse`.`quantity` AS `pivot_quantity`,
  `product_warehouse`.`location_info` AS `pivot_location_info`,
  `product_warehouse`.*,
  `products`.*
FROM
  `products`
  INNER JOIN `product_warehouse` ON `products`.`id` = `product_warehouse`.`product_id`
WHERE
  `product_warehouse`.`warehouse_id` = 1
ORDER BY
  `id` DESC
limit
  50 OFFSET 0
Was this page helpful?