You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Custom scope classes can be added to the global `Query`. The custom scope class will need to implement the `Scope` interface and contain the required `apply` method.
112
+
The `apply` method should accept the query `Builder` as the first argument and any optional arguments passed via the scope.
113
+
Once added to the `Query` class the scope will be available by the class name with the first letter lowecase.
114
+
115
+
```php
116
+
// Create a custom scope class.
117
+
use Query\Scope;
118
+
use Query\Builder;
119
+
120
+
class PostID implements Scope {
121
+
public function apply( Builder $builder, $id = null ) {
122
+
return $builder->where( 'p', $id );
123
+
}
124
+
}
125
+
126
+
// Add the scope to the Query.
127
+
Query::addScope( new PostID );
128
+
129
+
// Use the scope in the Query.
130
+
$results = Query::postID( 123 )->get();
131
+
```
132
+
93
133
## Notes
94
134
95
135
* The library is still in active development and not intended for production use.
0 commit comments