@@ -296,14 +296,29 @@ public function getRecords(FMBaseBuilder $query)
296296 // default to an empty array
297297 $ queryParams = [];
298298
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+
299318 // handle scripts
300319 if ($ query ->script !== null ) {
301320 $ queryParams ['script ' ] = $ query ->script ;
302321 }
303-
304- if ($ query ->getRecordId () !== null ) {
305- $ url .= (Str::endsWith ($ url , '/ ' ) ? '' : '/ ' ) . $ query ->getRecordId ();
306- }
307322 if ($ query ->scriptParam !== null ) {
308323 $ queryParams ['script.param ' ] = $ query ->scriptParam ;
309324 }
@@ -319,23 +334,13 @@ public function getRecords(FMBaseBuilder $query)
319334 if ($ query ->scriptPrerequestParam !== null ) {
320335 $ queryParams ['script.prerequest.param ' ] = $ query ->scriptPrerequestParam ;
321336 }
337+
322338 if ($ query ->layoutResponse !== null ) {
323339 $ queryParams ['layout.response ' ] = $ query ->layoutResponse ;
324340 }
325341 if ($ query ->portal !== null ) {
326342 $ queryParams ['portal ' ] = $ query ->portal ;
327343 }
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- }
339344
340345 $ response = $ this ->makeRequest ('get ' , $ url , $ queryParams );
341346
0 commit comments