I have recently setup a new Lumen project (v5.1.3) and noticed the instance methods from Eloquent\Builder provided to Eloquent\Model by using Model::__callStatic() and Model->__call() internally are not added to the phpDocs generated by ide-helper:models.
One example directly from the Larvel 5.1 documentation is the ::find() method.

My observation is this call to ::find() is caught by __callStatic() and __call() methods of Eloquent\Model and proxied to \Illuminate\Database\Eloquent\Builder.

These methods can be added to the phpDocs of the model with @method hints like the following:
/**
* @method static \Illuminate\Database\Eloquent\Model|\App\Models\Cafe find($id)
*/
My question is, should these magic methods from Builder be added to Model subclasses by ide-helper:models? Or should the Laravel documentation be updated instead?
Worth noting that this whole situation can also be avoided by using the builder directly via the query() method.
$cafe = Cafe::query()->find($cafeId);
The find() method was defined in 5.0 but are no longer defined on the
Eloquent\Modelas of 5.1.
I'll works if you extends from Eloquent facade. But I think that it need to works directly from Eloquent\Model too.
I think that having such methods in Model docblocks is a real overhead, because find is only one "magic" method from EloquentBuilder. Then somebody will want methods from the QueryBuilder which are also called with __call/__callStatic.
So the easiest workaround, if you need autocompletion, is to extend Eloquent instead ofEloquent\Model, as @rentalhost said. Or, if you don't want to extend Eloquent, you can set something like this to the docblock of your model:
/**
* App\User
*
* @mixin Eloquent
*/
Aha, such a tricky but useful workaround ~
@bebnev Very smart of the @mixin tag. Great work.
I believe @mixin is a neat solution. Shouldn't we close this issue?
@shehi it should generate the @mixin itself first IMO
@Francismori7 Agreed.
I have 5.1 and a BaseModel in the inheritance chain which extends from Eloquent. Even with this the methods like find will always make the ide think that the class returned is Eloquent/Model rather than the calling model class.
We have over 1K models encompassing our sites to sales to warehousing to logistics. For our 50+ developers this plugin is a godsend but imagine adding the two static method definitions we use the most to the models when a scheduled reset is run through artisan(!) and then you can understand how a godsend turns into a god's wrath...
@method static [model class]|null first($columns = array())
@method static [model class]|null find($id)
@barryvdh this is already fixed due to @mixin support long time ago, issue can be closed :}
Most helpful comment
I think that having such methods in Model docblocks is a real overhead, because find is only one "magic" method from EloquentBuilder. Then somebody will want methods from the QueryBuilder which are also called with __call/__callStatic.
So the easiest workaround, if you need autocompletion, is to extend
Eloquentinstead ofEloquent\Model, as @rentalhost said. Or, if you don't want to extendEloquent, you can set something like this to the docblock of your model: