Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update filtering.md to clarify handling of array scope parameter #976

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/features/filtering.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ You can even pass multiple parameters to the scope by passing a comma separated
GET /events?filter[schedule.starts_between]=2018-01-01,2018-12-31
```

When passing an array as a parameter you can access it, as an array, in the scope by using the spread operator.
```php
public function scopeInvitedUsers(Builder $query, ...$users): Builder
{
return $query->whereIn('id', $users);
}
```

When using scopes that require model instances in the parameters, we'll automatically try to inject the model instances into your scope. This works the same way as route model binding does for injecting Eloquent models into controllers. For example:

```php
Expand Down