Example of Local scopes in guillaumebriday/laravel-blog

File app/Models/Comment.php (link to Github)
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;

class Comment extends Model
    public function scopeLastWeek(Builder $query): Builder
        return $query->whereBetween('posted_at', [carbon('1 week ago'), now()])
File app/Http/Controllers/Admin/ShowDashboard.php (link to Github)
use App\Http\Controllers\Controller;
use App\Models\Comment;
use App\Models\Post;
use App\Models\User;

class ShowDashboard extends Controller
    public function __invoke(): View
        return view('admin.dashboard.index', [
            'comments' =>  Comment::lastWeek()->get(),
            'posts' => Post::lastWeek()->get(),
            'users' => User::lastWeek()->get(),

Additional resources on local scopes: