I have a model (App\Models\Post) that extends a model from a composer package (LaraZeus\Sky\Models\Post). I'm trying to adjust one of the built-in scopes, so I thought I just needed to redeclare the method in my extension class but when I do I get this error
PHP Fatal error: Declaration of App\Models\Post::scopeRelated(Illuminate\Database\Eloquent\Builder $query, App\Models\Post $post): Illuminate\Database\Eloquent\Builder must be compatible with LaraZeus\Sky\Models\Post::scopeRelated(Illuminate\Database\Eloquent\Builder $query, LaraZeus\Sky\Models\Post $post): Illuminate\Database\Eloquent\Builder in /home/aaron/nftnews/app/Models/Post.php on line 118
I just copied and pasted the original scope from the parent model and added a second where clause. so this
* @param Builder<Post> $query
*/
public function scopeRelated(Builder $query, Post $post): Builder
{
return $query->where('post_type', 'post')
->withAnyTags($post->tags->pluck('name')->toArray(), 'category');
}
turned into this
* @param Builder<Post> $query
*/
public function scopeRelated(Builder $query, Post $post): Builder
{
return $query->where('post_type', 'post')
->where('create_at', '>', now()-<subyear())
->withAnyTags($post->tags->pluck('name')->toArray(), 'category');
}
Can anyone tell me why this doesn't work?