Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

add field to many to many relationship laravel

//in Model
public function products()
{
    return $this->belongsToMany(Product::class)
        ->withPivot('status')
        ->withTimestamps();
}
//in Migration
Schema::create('vendor_product', function (Blueprint $table) {
    $table->unsignedBigInteger('product_id');
    $table->foreign('product_id', 'product_id_fk_6766249')->references('id')->on('products')->onDelete('cascade');
    $table->unsignedBigInteger('vendor_id');
    $table->foreign('vendor_id', 'vendor_id_fk_6766249')->references('id')->on('vendors')->onDelete('cascade');
    $table->string('status');
    $table->timestamps();
});
 
PREVIOUS NEXT
Tagged: #add #field #relationship #laravel
ADD COMMENT
Topic
Name
5+5 =