@@ -296,14 +296,29 @@ public function getRecords(FMBaseBuilder $query)
296
296
// default to an empty array
297
297
$ queryParams = [];
298
298
299
+ // handle single record requests
300
+ if ($ query ->getRecordId () !== null ) {
301
+ $ url .= (Str::endsWith ($ url , '/ ' ) ? '' : '/ ' ) . $ query ->getRecordId ();
302
+ } else {
303
+ // handle pagination and sorting
304
+ // these parameters are not used for single record requests
305
+ if ($ query ->offset > 0 ) {
306
+ // Offset is 1-indexed
307
+ $ queryParams ['_offset ' ] = $ query ->offset + 1 ;
308
+ }
309
+ if ($ query ->limit > 0 ) {
310
+ $ queryParams ['_limit ' ] = $ query ->limit ;
311
+ }
312
+ if ($ query ->orders !== null && count ($ query ->orders ) > 0 ) {
313
+ // sort can have many values, so it needs to get json_encoded and passed as a single string
314
+ $ queryParams ['_sort ' ] = json_encode ($ query ->orders );
315
+ }
316
+ }
317
+
299
318
// handle scripts
300
319
if ($ query ->script !== null ) {
301
320
$ queryParams ['script ' ] = $ query ->script ;
302
321
}
303
-
304
- if ($ query ->getRecordId () !== null ) {
305
- $ url .= (Str::endsWith ($ url , '/ ' ) ? '' : '/ ' ) . $ query ->getRecordId ();
306
- }
307
322
if ($ query ->scriptParam !== null ) {
308
323
$ queryParams ['script.param ' ] = $ query ->scriptParam ;
309
324
}
@@ -319,23 +334,13 @@ public function getRecords(FMBaseBuilder $query)
319
334
if ($ query ->scriptPrerequestParam !== null ) {
320
335
$ queryParams ['script.prerequest.param ' ] = $ query ->scriptPrerequestParam ;
321
336
}
337
+
322
338
if ($ query ->layoutResponse !== null ) {
323
339
$ queryParams ['layout.response ' ] = $ query ->layoutResponse ;
324
340
}
325
341
if ($ query ->portal !== null ) {
326
342
$ queryParams ['portal ' ] = $ query ->portal ;
327
343
}
328
- if ($ query ->offset > 0 ) {
329
- // Offset is 1-indexed
330
- $ queryParams ['_offset ' ] = $ query ->offset + 1 ;
331
- }
332
- if ($ query ->limit > 0 ) {
333
- $ queryParams ['_limit ' ] = $ query ->limit ;
334
- }
335
- if ($ query ->orders !== null && count ($ query ->orders ) > 0 ) {
336
- // sort can have many values, so it needs to get json_encoded and passed as a single string
337
- $ queryParams ['_sort ' ] = json_encode ($ query ->orders );
338
- }
339
344
340
345
$ response = $ this ->makeRequest ('get ' , $ url , $ queryParams );
341
346
0 commit comments