Skip to content

Instantly share code, notes, and snippets.

@VaguelyOnline
Created October 30, 2014 15:38
Show Gist options
  • Save VaguelyOnline/57bab38f664f6531cb89 to your computer and use it in GitHub Desktop.
Save VaguelyOnline/57bab38f664f6531cb89 to your computer and use it in GitHub Desktop.
class User {
...
public function sites() {
return $this->hasManyThrough('Site', 'Account');
}
public function hasSite($site) {
return $this->sites()->whereId($site->id)->count() != 0;
}
}
// Elsewhere...
// the following says that the 'id' clause in the were is ambiguous
// (both models have an ID) - how can I cause my search to be constrained
// to if the user is distantly related to the Site model with the given ID?!
echo User::first()->hasSite(Site::first());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment