From 9156635fd1245247c651af5e5e8ada83e1cfbd48 Mon Sep 17 00:00:00 2001 From: Gustav Gullstrand Date: Tue, 8 Oct 2024 09:42:24 +0200 Subject: [PATCH] Update filtering.md to clarify handling of array scope parameter Problem discussed here https://github.com/spatie/laravel-query-builder/issues/334 --- docs/features/filtering.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/features/filtering.md b/docs/features/filtering.md index e51e57fe..fd34edf3 100644 --- a/docs/features/filtering.md +++ b/docs/features/filtering.md @@ -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