Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sr57's avatar
Level 39

Larastan / ORM

Hi all,

I use Larastan for the first time. It found me a bug, good, but ir also complains about this syntax :

Flight::where('active', 1)...

Call to an undefined static method App\Models\Flight::where()

Any explanation? solution?

Thanks in advance.

0 likes
13 replies
chaudigv's avatar

Is there a where() method in your Flight model?

sr57's avatar
Level 39

Hi @chaudigv

It's a 'standard' model/migration and I have no pb with the app, 'Flight::where('active', 1)...' works well, it's only Larastan that gives this msg.

class Flight extends Model
{
    use HasFactory;
}

If you use Larastan and can you tell me if you don't see such msg?

If so, I'll have to go deeper with your question.

mabdullahsari's avatar

Flight::where has to go through 2 or 3 magic methods before actually calling where on the QueryBuilder. That's why it has a hard time in that case. We can help Larastan by explicitly instantiating a new QueryBuilder instance.

Flight::query()->where('active', true); // ::query() tells we have a QueryBuilder at our disposal
sr57's avatar
Level 39

HI @mabdullahsari

OK, but I don't use a lot ORM (I have better 'direct sql' ) , when I use ORM it's only for simple cases and I don't want to make it less simple just for Larastan

Do you know if I can 'comment' this rule in Larastan, if not, I'll make a little script in bash to filter these msg.

sr57's avatar
Level 39

'complex' is probably not the right word, but if I use Eloquent ORM, it's to have the shortest syntax, in addition, conform to the doc.

Thanks for the link.

Kobayakawa's avatar

Hi,

where static method on model is definitely supported in Larastan. Can you tell me your Larastan/PHPStan version and maybe give your phpstan.neon config file if you have one?

1 like
sr57's avatar
Level 39

Hi @kobayakawa

Thanks for your answer.

Good news

phpstan --version; echo; cat phpstan.neon.dist

PHPStan - PHP Static Analysis Tool 0.12.76

#210215 phpstan.neon.dist - larastan config
parameters:

    paths:
        - app

    # The level 8 is the highest level
    level: 1

    ignoreErrors:
 #       - '#Unsafe usage of new static#'
 #       - 'undefined static method'			# Orm where 

    excludePaths:
        - storage
        - vendor
        - ./routes/console.php				# undefined variable $this - to be explained

    checkMissingIterableValueType: false
Kobayakawa's avatar

You don't need to add vendor to excludePaths I think that's your issue.

sr57's avatar
Level 39

@kobayakawa

I have already done this try, unfortunately, it doesn't solve the pb.

It changes the analysis duration and the total number of errors : 91 -> 1692! , so mainly not mine.

without vendor : cat larastan_v0.res | grep where

  29     Call to an undefined static method App\Models\Log::where().  
  37     Call to an undefined static method App\Models\Log::where().  
  43     Call to an undefined static method App\Models\Log::where().  
  140    Call to an undefined static method App\Models\Robot::where().                                       
  29     Call to an undefined static method App\Models\Robot::where().  
  37     Call to an undefined static method App\Models\Robot::where().  
  43     Call to an undefined static method App\Models\Robot::where(). 

with vendor : cat larastan_v1.res | grep where

  29     Call to an undefined static method App\Models\Log::where().  
  37     Call to an undefined static method App\Models\Log::where().  
  43     Call to an undefined static method App\Models\Log::where().  
  140    Call to an undefined static method App\Models\Robot::where().                                       
  29     Call to an undefined static method App\Models\Robot::where().  
  37     Call to an undefined static method App\Models\Robot::where().  
  43     Call to an undefined static method App\Models\Robot::where().  
  1732   Call to an undefined method Illuminate\Database\Eloquent\Model::where().
Kobayakawa's avatar
Level 8

@sr57 That is really weird. You have paths: app in the config so it shouldn't even scan the vendor directory. Do you have a folder called vendor in your app folder?

And I noticed something. In the phpstan config you posted above you don't include the Larastan extension. It is fine if you also use phpstan/extension-installer but if not you need to add

includes:
    - ./vendor/nunomaduro/larastan/extension.neon

to your config file

2 likes
Taelkir's avatar

@Kobayakawa Just a note here, includes goes outside of parameters.

i.e.

includes:
    - ./vendor/nunomaduro/larastan/extension.neon
parameters:
    checkMissingIterableValueType: true
    paths:
        - app
    level: 1

Tripped me up trying to put includes as a child of parameters. But this did fix 49 "Call to an undefined static method" errors I was experiencing. :)

sr57's avatar
Level 39

That is really weird. ...

makes me thinking I have a general problem with the package.

I reinstall it in a new project and it works (no more pb with 'where') but I always need to exclude vendor ... It seems to be another pb, maybe a future post but today exclude vendor in my config file doesn't annoy me.

Thanks

PS : I don't understand what's wrong with my first try but it is probably due to the fact that on the way to transform all my old php scripts in Laravel, I have also some old bash <<scripts that are not fully ok with composer.

Please or to participate in this conversation.