kirschbaum-development / eloquent-power-joins

The Laravel magic you know, now applied to joins.
MIT License
1.38k stars 87 forks source link

defined return types prevent IDE from autocompleting #186

Closed azgooon closed 2 weeks ago

azgooon commented 2 weeks ago

Hi,

I checked resolved issues and no one brought this up so I think I am just missing the puzzle rather than reporting an issue. I noticed that when I use i.e joinRelation() method in my laravel project, the chained method (ie groupBy()) afterwards is marked as not defined. This is because joinRelation() returns closure instead of Builder instance. What is the best way to overcome this issue and make IDE "understand" that joinRelation() returns Query Builder and can be chained?

image

Thanks, Tom.

luisdalmolin commented 2 weeks ago

The best way (right now) to overcome this is to add this to your model as a docblock (make sure to use the right model name):

/**
 * @method static \Illuminate\Database\Eloquent\Builder|User joinRelation(string $relationName, \Clousure|array$callback = null, string $joinType = 'join', bool $useAlias = false, bool $disableExtraConditions = false, string $morphable = null)
 */
class User extends Model
{
}
azgooon commented 2 weeks ago

@luisdalmolin this works a treat - thank you very much.