laravel-ide-helper icon indicating copy to clipboard operation
laravel-ide-helper copied to clipboard

Support of staudenmeir/eloquent-has-many-deep

Open hichxm opened this issue 2 years ago • 5 comments

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.

hichxm avatar Nov 01 '22 17:11 hichxm

I know you are lazy : https://github.com/staudenmeir/eloquent-has-many-deep

hichxm avatar Nov 01 '22 17:11 hichxm

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 avatar Nov 07 '22 10:11 daniel-de-wit

@daniel-de-wit I just try to use it, I create new issue and pull request to fix one bug. It now works.

hichxm avatar Nov 07 '22 18:11 hichxm

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

Jefemy avatar Nov 14 '22 02:11 Jefemy

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.

staudenmeir avatar Dec 11 '23 21:12 staudenmeir