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
// $users will be sorted by name in ascending order with a secondary sort on street in descending order.
260
260
```
261
261
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
+
262
284
### Other query methods
263
285
264
286
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