---
title: "Query scopes — Requests for Laravel | Roundly"
description: "Filter requests by status, author and deadline with ready-made Eloquent scopes."
url: https://roundly-consulting.com/open-source/docs/requests-for-laravel/query-scopes
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Requests for Laravel](https://roundly-consulting.com/open-source/docs/requests-for-laravel.md)

# Query scopes

```php
use RoundlyConsulting\Requests\Enums\Status;
use RoundlyConsulting\Requests\Models\Request;

Request::query()->withStatus(Status::New)->get();
Request::query()->pending()->get();
Request::query()->approved()->get();
Request::query()->rejected()->get();
Request::query()->cancelled()->get();
Request::query()->expired()->get();              // open + past expires_at
Request::query()->expiringBefore(now()->addDay())->get();
Request::query()->authoredBy($user)->get();
```

| Scope | Matches |
| --- | --- |
| `withStatus(Status $status)` | Requests in the given status. |
| `pending()` | Status New — open, awaiting a decision. |
| `approved() / rejected() / cancelled()` | Status Approved / Rejected / Cancelled. |
| `expired()` | Still New and past expires\_at — the requests due for expiry, not rows already in status Expired. Use withStatus(Status::Expired) for those. |
| `expiringBefore(CarbonInterface $moment)` | Still New with expires\_at before the given moment. |
| `authoredBy(Model $author)` | Requests raised by the given author (type + id). |

## Combining scopes

Scopes chain with each other and with plain query-builder calls:

```php
// Alice's open claims that lapse within 48 hours:
Request::query()
    ->authoredBy($alice)
    ->pending()
    ->expiringBefore(now()->addHours(48))
    ->where('type', 'Claim')
    ->get();
```

On the author side, $user->openRequests(), approvedRequests() and rejectedRequests() give the same filters as relations (Model setup).

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/requests-for-laravel.md)
