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
Copy file name to clipboardExpand all lines: docs/intro.md
+104-4Lines changed: 104 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,110 @@ sidebar_position: 1.0
5
5
6
6
# Query Builder
7
7
8
-
:::danger
9
8
10
-
This package is currently under development. If anything works, that's a surprise.
9
+
[Query Builder](https://github.com/Javaabu/query-builder) Modifications on top of spatie/query-builder.
10
+
Provides helper classes for creating API controllers and supports [Scribe](https://github.com/knuckleswtf/scribe/) for automatically generating API docs.
11
11
12
-
:::
12
+
For example, if you have a `Product` model, you can create an API controller like so:
13
13
14
-
[Query Builder](https://github.com/Javaabu/query-builder) Modifications on top of spatie/query-builder.
14
+
```php
15
+
<?php
16
+
17
+
namespace App\Http\Controllers\Api;
18
+
19
+
use Javaabu\QueryBuilder\Http\Controllers\ApiController;
20
+
use App\Models\Product;
21
+
use Illuminate\Database\Eloquent\Builder;
22
+
use Spatie\QueryBuilder\AllowedFilter;
23
+
24
+
class ProductsController extends ApiController
25
+
{
26
+
/**
27
+
* Get the base query
28
+
*
29
+
* @return Builder
30
+
*/
31
+
public function getBaseQuery(): Builder
32
+
{
33
+
return Product::query();
34
+
}
35
+
36
+
/**
37
+
* Get the allowed fields
38
+
*
39
+
* @return array
40
+
*/
41
+
public function getAllowedFields(): array
42
+
{
43
+
return array_diff(\Schema::getColumnListing('products'), (new Product)->getHidden());
0 commit comments