Okipa / laravel-table

Generate tables from Eloquent models.
MIT License
527 stars 64 forks source link

Eager load relations #78

Closed RSickenberg closed 2 years ago

RSickenberg commented 2 years ago

Hello.

I'm trying to Eager load on the ->query() method but:

  1. I cannot use the Builder to set Eager loading
  2. 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 2 years ago

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 2 years ago

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.