laravel-enum
laravel-enum copied to clipboard
Error when running PHPstan on a Model using `QueriesFlaggedEnums` trait
I'm using the QueriesFlaggedEnums
trait in the Badge
model. I've defined a local scope which use the hasAnyFlags()
. PHPstan raises an error like:
------ ----------------------------------------------------------------------------------
Line app/Models/Badge.php
------ ----------------------------------------------------------------------------------
109 Call to an undefined method Illuminate\Database\Eloquent\Builder::hasAnyFlags().
------ ----------------------------------------------------------------------------------
This is the Laravel code:
107: public function scopeWithActuatorsIn(Builder $query, array $actuators): Builder
107: {
109: return $query
110: ->where('active', true)
111: ->hasAnyFlags('actuators', $actuators);
112: }
Someone was suggesting the use of PHP generics in order to avoid the problem. I've tried this approach using an stub file but nothing has changed.
The code could be find here: https://github.com/pacoorozco/gamify-laravel
Related to: nunomaduro/larastan#1307
Have you tried adding generics to your own code? I think we should try and add them to this library too, but without having them in your code there is nothing to work with. This library cannot magically conjure up a connection from any Builder
object to one where the generic TModel
is provided.
You have shared a very good point. I didn't think about it, let me try it. 🧑🏭
Closing, as I no longer plan to develop this library further - see https://github.com/BenSampo/laravel-enum/issues/332.