Dynamically loop relationships

Posted 8 months ago by jlanzas

Is it possible to dynamically loop relationships from a modelo? This is what a will like to accomplish, I have the following append in many of my model

Product.php

protected $appends = [
    'permissions'
];

Which is working great but I don't need this $append to be added when Eager Loading. I know setAppends([]) removes this field.

What I want to do is something like

foreach ($model->relationships() as $relationship) {
    $relationship->setAppends([]);
}

Since, this is going to be a global function I don't specifically know the amount of relations there have been set. So that the reason I want to loop the model dynamically.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.