سؤال

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
}
هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top