Answer the question
In order to leave comments, you need to log in
How to properly link a table in laravel?
Let's start over:
I write in migration
Schema::table('partner_products', function (Blueprint $table) {
$table->integer('partner_products_statuses_id')->default(4);
$table->foreign('partner_products_statuses_id')
->references('id')->on('partner_products_statuses');
});
public function partnerProductsStatus()
{
return $this->hasOne(PartnerProductsStatus::class, 'id' , 'partner_products_statuses_id');
}
public function partnerProduct()
{
return $this->belongsTo(PartnerProduct::class, 'partner_products_statuses_id', 'id');
}
partner_id integer not null
constraint partner_products_partner_id_foreign
references partners
on update cascade on delete cascade,
product_status varchar(255)
Answer the question
In order to leave comments, you need to log in
Why do you need a pivot table? You have a one to many relationship, not many to many.
Remove the migration completely, replace the methods with
public function partnerProductsStatus()
{
return $this->hasOne(PartnerProductsStatus::class);
}
public function partnerProduct()
{
return $this->belongsTo(PartnerProduct::class);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question