I have database like thisaccounts
- id
- name
contacts
- id
- account_idaccount_communications
- id
- account_id
and contact model :
class Contact extends Model
{
public function Account()
{
return $this->belongsTo('App\Account');
}
public function AccountCommunication()
{
return $this->hasManyThrough( 'App\AccountCommunication','App\Account');
}
}
Account model
class Account extends Model
{
public function AccountCommunication()
{
return $this->hasMany('App\AccountCommunication');
}
public function Contact()
{
return $this->hasMany('App\Contact');
}
}
AccountCommunication model
class AccountCommunication extends Model
{
public function Account()
{
return $this->belongsToMany('App\Account');
}
}
On my controller
class ContactController extends Controller
{
public function index()
{
$contacts = Contact::with('Account')->with('AccountCommunication')->paginate(10);
dd($contacts);
}
}
Show me this error
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'accounts.contact_id' in 'field list' (SQL: select
account_communications.*,accounts.contact_idfromaccount_communicationsinner joinaccountsonaccounts.id=account_communications.account_idwhereaccounts.contact_idin (20))
account_communicationsthe intermediate table? - Sanzeeb Aryal