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

alnahian2003's avatar

Named parameter is not working for Query Scope parameters

In my User model I wrote this query scope with named parameters but seems like it doesn't return anything when I tinker it

 public function scopeActive(Builder $query): void
    {
        $query->where(column: 'is_active', value: true);
    }

But, without using any named parameters, it just works fine! But why?

 $query->where('is_active',  true);

//btw I have PHP 8.1.x installed and Laravel X is up and running.

0 likes
2 replies
alnahian2003's avatar
alnahian2003
OP
Best Answer
Level 3

Okay, so seems like I also need to pass another named parameter operator in order to get the expected result:

return $query->where(column: 'is_active', operator:"=", value: true);

As of PHP.net stated in their Function Arguments docs:

PHP 8.0.0 introduced named arguments as an extension of the existing positional parameters. Named arguments allow passing arguments to a function based on the parameter name, rather than the parameter position. This makes the meaning of the argument self-documenting, makes the arguments order-independent, and allows skipping default values arbitrarily.

Please or to participate in this conversation.