Question

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
}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top