Rookwood
Rookwood

Reputation: 683

Testing for relation between Eloquent objects (Laravel 4)

In Laravel 4, is there a method that allows you to test for a relationship between two Eloquent objects without knowing the type of relationship beforehand?

For example, a user model would have a 1:1 relation with a profile and a 1:m relation with comments. I'm looking for some way to do something along the lines of the following:

if ($user->isRelatedTo($someOtherObject))
{
    // stuff
}

Upvotes: 0

Views: 180

Answers (1)

LHolleman
LHolleman

Reputation: 2596

Unfortunately there is not, relations are not managed in config files thus it is impossible to test. You could however make these config files yourself and extend Eloquent to implement this method.

Upvotes: 1

Related Questions