Why do Laravel ask for a pivot table as singular, in my code? How do I fix so it call as plural?
Database tables
- users (id, etc)
- campaigns (id, etc)
- campaign_users (user_id, campaign_id)
Code
My campaign model, and campaign_user model are pretty much empty, and generated by artisan. But here are my user relation to campaigns, in User model:
public function playing_campaigns()
{
return $this->belongsToMany('Sagohamnen\campaign\campaign');
}
Here I call DB to get the campaigns, in which the user are part of:
$user = user::with(['playing_campaigns'])->where('id', $id)->get();
SQL error
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sagohamnen.campaign_user' doesn't exist (SQL: select
campaigns
.*,campaign_user
.user_id
aspivot_user_id
,campaign_user
.campaign_id
aspivot_campaign_id
fromcampaigns
inner joincampaign_user
oncampaigns
.id
=campaign_user
.campaign_id
wherecampaign_user
.user_id
in (1))