0

I was trying to setup a BelongsToMany relationship where one of the columns is not an ID reference, but rather a string reference.

return $this->belongsToMany('User', 'chats_users', 'chat_id', 'user_email');

Is it possible to do this?

Matthew Brown
  • 4,876
  • 3
  • 18
  • 21

1 Answers1

2

This should work as long as the string reference is a primary key of the parent table although it's not recommended. Be sure to check this explanation on using strings as primary keys

return $this->belongsToMany('User', 'chats_users', 'chat_id', 'user_email');
Community
  • 1
  • 1