Skip to content

Commit 9463368

Browse files
authored
fetchData (#111)
use CRUD style for GET-ing record
1 parent f908e0f commit 9463368

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/App/Models/RemoteType.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,19 @@ private function fetchData(?string $value = null, bool $search = false)
6262
if ($this->method == 'POST') {
6363
empty($body) ? ($body = [$qParam => $value]) : ($body[$qParam] = $value);
6464
} else {
65-
$parsed = parse_url($url);
66-
parse_str($parsed['query'] ?? '', $params);
67-
$params[$qParam] = $value;
68-
$url = $parsed['scheme'] . '://' . $parsed['host'];
69-
if (!empty($parsed['port'])) {
70-
$url .= ':' . $parsed['port'];
65+
if (!$search) {
66+
// use CRUD style for GET-ing record
67+
$url = rtrim($url, '/') . '/' . $value;
68+
} else {
69+
$parsed = parse_url($url);
70+
parse_str($parsed['query'] ?? '', $params);
71+
$params[$qParam] = $value;
72+
$url = $parsed['scheme'] . '://' . $parsed['host'];
73+
if (!empty($parsed['port'])) {
74+
$url .= ':' . $parsed['port'];
75+
}
76+
$url .= $parsed['path'] . '?' . http_build_query($params);
7177
}
72-
$url .= $parsed['path'] . '?' . http_build_query($params);
7378
}
7479
}
7580

0 commit comments

Comments
 (0)