where('status', 'active'); } /** * Scope a query to only include products of a given category. * * @param \Illuminate\Database\Eloquent\Builder $query * @param string $category * @return void */ public function scopeCategory(Builder $query, string $category) { $query->where('category', $category); } } // Usage: $activeProducts = Product::active()->get(); $electronics = Product::active()->category('electronics')->get(); $paginatedBooks = Product::category('books')->paginate(10);