staudenmeir / eloquent-has-many-deep

Laravel Eloquent HasManyThrough relationships with unlimited levels

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IDE helpers

nandi95 opened this issue · comments

Just like in the adjacency package it would be great if a hook can be added to this package as currently the relations from this package are not being picked up.

Hi @nandi95,
Good idea, I released a new version with the hook:
https://github.com/staudenmeir/eloquent-has-many-deep#ide-helper

This fails for me on a getter,
I have a cost and a unit_amount column in the db and on the model I have an accessor getUnitCostAttribute. This does: return $this->cost / $this->unit_amount;

Exception: Division by zero
Could not analyze class App\Models\Ingredient.

Trace:
#0 [internal function]: App\Models\Ingredient->getUnitCostAttribute()
#1 /Users/user/Web/project/vendor/staudenmeir/eloquent-has-many-deep/src/IdeHelper/DeepRelationsHook.php(35): ReflectionMethod->invoke(Object(App\Models\Ingredient))
#2 /Users/user/Web/project/vendor/barryvdh/laravel-ide-helper/src/Console/ModelsCommand.php(1587): Staudenmeir\EloquentHasManyDeep\IdeHelper\DeepRelationsHook->run(Object(Barryvdh\LaravelIdeHelper\Console\ModelsCommand), Object(App\Models\Ingredient))

Please try replacing line 36 of vendor/staudenmeir/eloquent-has-many-deep/src/IdeHelper/DeepRelationsHook.php with this:

} catch (\Throwable) {

I released a new version with this fix.

That did fix it, thanks.