Closed
Description
Laravel Version
12.8.1
PHP Version
8.4.2
Database Driver & Version
No response
Description
Previously, we were able to call scope methods statically (basic example):
public function scopeActive(Builder $query): Builder {
return $query->whereNotNull('active');
}
We could call:
User::active()->get();
If we change this to using the Scope Attribute, this no longer works:
#[Scope]
public function active(Builder $query): Builder {
return $query->whereNotNull('active');
}
User::active()->get();
// Non-static method App\Models\User::active() cannot be called statically
The fix for this is using query()
so:
User::query()->active()->get();
I guess I opened this issue because I found it strange as I was expecting it to work the same, also the documentation suggests it to work fine
I understand why it's doing it, ie because __callStatic
isn't actually getting called because the method actually exists, but opened this for visibility / a point of discussion as ideally it would be nice for it to work as it did before 🤷🏻
Steps To Reproduce
- Create a model
- Create a method using the scope attribute
- Try to call the method statically on the model
- Witness an error
Metadata
Metadata
Assignees
Labels
No labels