Eager load relations
RSickenberg opened this issue · 2 comments
RSickenberg commented
Hello.
I'm trying to Eager load on the ->query()
method but:
- I cannot use the
Builder
to set Eager loading - I would like to make
$myModel::with('myRelation')
and use it on the table afterward.
Do you know how can I manage this?
Regards
RSickenberg commented
Okay I found the solution like this. In case other people need this ;-)
$builder->with('getRelation')->where('col', '=', 'value');
And then:
$table->column()->title('title')->html(function (Model $model) { return $model->getRelationValue('relation')->myProp; });
Okipa commented
Hi @RSickenberg, sorry for the late answer !
That's indeed the way to lazy load a relationship, thanks for answering to other people with a potential similar issue.