You are viewing documentation for an outdated version. It is no longer supported!

Select

Provided that the API you are working with supports such, you may select the "fields" to be returned by a response. Typically, you would combine a selection of fields with include.

Select a Single Field

The select() method allows you to specify what field(s) should be returned.

$response = $client
        ->select('name')
        ->get('/users');
default
/users?select=name
json api
/users?fields[]=name
odata
/users?$select=name

Select Field from Resource

You may also specify what resource the given field should be selected from.

$response = $client
        ->select('name', 'friends')
        ->get('/users');
default
/users?select=friends.name
json api
/users?fields[friends]=name
odata
/users?$select=friends.name

Select Multiple Fields

To select multiple fields, you can state an array as argument.

$response = $client
        ->select([
            'name' => 'friends',
            'age' => 'friends',
            'job_title' => 'position'
        ])
        ->get('/users');
default
/users?select=friends.name,friends.age,position.job_title
json api
/users?fields[friends]=name,age&fields[position]=job_title
odata
/users?$select=friends.name,friends.age,position.job_title

Select Raw Expression

To perform a raw selection, use the selectRaw() method. It accepts a string expression and an optional bindings array.

$response = $client
        ->selectRaw('account(:number)', [ 'number' => 7 ])
        ->get('/users');
default
/users?select=account(7)
json api
/users?fields[]=account(7)
odata
/users?$select=account(7)