laravel-ide-helper
laravel-ide-helper copied to clipboard
Support of staudenmeir/eloquent-has-many-deep
Today, I implement barryvdh/laravel-ide-helper in my personal project after using it in mine work. I'm using staudenmeir/eloquent-has-many-deep package for query optimization with new relations "HasOneDeep", "HasManyDeep" and more.
For more understanding, see following code :
/**
* @mixin IdeHelperBusiness
*/
class Business extends Model
{
public function region(): HasManyThrough
{
return $this->hasOneDeep(Region::class, [City::class, Department::class], ['id', 'id', 'id'], ['city_id', 'department_id', 'region_id']);
}
public function department(): HasManyThrough
{
return $this->hasOneDeep(Department::class, [City::class], ['id', 'id'], ['city_id', 'department_id']);
}
public function city()
{
return $this->belongsTo(City::class);
}
}
Maybe you already see the problem, I need to set up manually the return type to HasManyThrough instead of HasOneDeep relation. If I don't do that, barryvdh/laravel-ide-helper will not be understood in my method.
I want to add HasOneDeep and more in barryvdh/laravel-ide-helper. I go to make pull request about it if you agree :+1:, else how I can implement it locally?
Sorry, bad English. Google Translate if my best friend.
I know you are lazy : https://github.com/staudenmeir/eloquent-has-many-deep
I made a model hook for this a while back. I just published it on Packagist, give it a try.
https://github.com/daniel-de-wit/laravel-ide-helper-hook-eloquent-has-many-deep
@daniel-de-wit I just try to use it, I create new issue and pull request to fix one bug. It now works.
This should be possible to fix without a model hook by adding the relationships to the config file
https://github.com/barryvdh/laravel-ide-helper#custom-relationship-types
Update eloquent-has-many-deep
to version 1.19
if you are on Laravel 10. Thanks to @daniel-de-wit, the package now automatically integrates into the IDE helper.