Skip to content

Commit e877206

Browse files
Update changelog & readme for selecting columns
1 parent 24dadfe commit e877206

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `laravel-query-builder` will be documented in this file
44

5+
## 1.6.0 - 2018-03-05
6+
7+
- add support for selecting specific columns using `?fields[table]=field_name`
8+
59
## 1.5.3 - 2018-02-09
610

711
- allow arrays in filters

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,28 @@ $users = QueryBuilder::for(User::class)
259259
// $users will be sorted by name in ascending order with a secondary sort on street in descending order.
260260
```
261261

262+
### Selecting specific columns
263+
264+
Sometimes you'll want to fetch only a couple fields to reduce the overall size of your SQL query. This can be done using the `fields` query parameter. The following fetch only the users' `id` and `name`
265+
266+
```
267+
GET /users?fields[users]=id,name
268+
```
269+
270+
The SQL query will look like this:
271+
272+
```sql
273+
SELECT "id", "name" FROM "users"
274+
```
275+
276+
Selecting fields for included models works the same way. This is especially useful when including entire relationships when you only need a couple of columns. Consider the following example:
277+
278+
```
279+
GET /posts?include=author&fields[author]=name
280+
```
281+
282+
All posts will be fetched including only the name of the author.
283+
262284
### Other query methods
263285

264286
As the `QueryBuilder` extends Laravel's default Eloquent query builder you can use any method or macro you like. You can also specify a base query instead of the model FQCN:

0 commit comments

Comments
 (0)