Support the ongoing development of Laravel.io →
Eloquent
Last updated 2 years ago.
0

perhaps the clue is that you have named your field Character_Id but in the code you are saying 'CharacterId'.. you dont really need that btw if your field is actually character_id (note the lower case)

0

shez1983 said:

perhaps the clue is that you have named your field Character_Id but in the code you are saying 'CharacterId'.. you dont really need that btw if your field is actually character_id (note the lower case)

Thank you for your reply, i'm sorry for the mistake i edited the post, the field name ios actually CharacterId not Character_Id

0
return $this->belongsTo('App\Guild', 'guild_members', 'CharacterId', 'GuildId');  

is wrong... 'CharacterId', 'GuildId are not the same things but needs to be other way around..

0

The problem is your relationship.

  1. Can a character be a part of many guilds? If no (so one character can only be in one guild), then you don't need a pivot table. You setup a belongsto and hasmany relationship with no pivot table.
  2. If yes (one character can be a part of many guilds), then you need to setup a belongsToMany relationship both ways with a pivot table.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.