Skip to content

Instantly share code, notes, and snippets.

@cmbirk
Created July 10, 2014 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmbirk/e5b39ea77aee1e1c49aa to your computer and use it in GitHub Desktop.
Save cmbirk/e5b39ea77aee1e1c49aa to your computer and use it in GitHub Desktop.
Trying to combine multiple ManyToMany Relationships
public function sponsor()
{
$sponsor = $this->belongsToMany('Group')->first();
if(!$sponsor) {
return $this->belongsToMany('User');
}
return $this->belongsToMany('Group');
}
public function userSponsor()
{
return $this->belongsToMany('User');
}
public function groupSponsor()
{
return $this->belongsToMany('Group');
}
@cmbirk
Copy link
Author

cmbirk commented Jul 10, 2014

The interface limits the sponsor to either a User or a Group.

@cmbirk
Copy link
Author

cmbirk commented Jul 10, 2014

Simply trying to call sponsor() should return either the User sponsor or the Group sponsor. Currently it won't return a User sponsor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment