2

I have two tables products and orders which are linked by a pivot table order_product with the id of each table. But I also want to add an amout column to the pivot table. How can I do this with laravel Voyager?

Ahmed Ibrahim
  • 43
  • 1
  • 5

1 Answers1

0

Easily just define it in your migration file of order_product and access it from relation function as bellow:

Schema::create('order_product', function (Blueprint $table) {
    $table->unsignedBigInteger('order_id');
    $table->unsignedBigInteger('product_id');
    $table->unsignedInteger('amount');
});

and for example in your product model:

public function orders()
{
    return $this->belongsToMany(Order::class)
        ->withPivot('amount');
}
kazemm
  • 473
  • 5
  • 19