2

I have Accounts table and Site_links table. When I use this code in Account Model:

public function site_links(){
    return $this->belongsToMany($SitelinkModel, 'account_site_link', 'account_id', 'site_link_id')->withTimestamps();
}

The values ​​of the two IDs are reversed.

1 Answers1

1

I got the answer, so the problem is

the belonsToMany parameters must be like this (Model, id_num_of_this_table, id_num_of_the_other_table);

sample in my account model

public function site_links(){
    return $this->belongsToMany($SitelinkModel, 'account_site_link', 'site_link_id', 'account_id')->withTimestamps();
}