Level 10
Did you ensure that the #[Scope] attribute was imported?
use Illuminate\Database\Eloquent\Attributes\Scope;
1 like
For some reason I cannot get the new method of indicating scopes to work, but the old way works just fine. I thought I just followed the documentation example, but I'm getting a missing arguments error as a result of the Builder $query argument. I'm on Laravel 12.8.1. Does anyone know what's going on?
Model:
#[Scope]
protected function published(Builder $query): void
{
$query->where('published_on', '!=', '');
}
#[Scope]
protected function newestFirst(Builder $query): void
{
$query->orderBy('published_on','desc');
}
Service class:
public function scopeTest():Collection {
return Post::published()->newestFirst()->get();
}
Error:
Too few arguments to function App\Models\Post::published(), 0 passed in D:\repos\aldint\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php on line 2465 and exactly 1 expected
Please or to participate in this conversation.