Closed robsontenorio closed 7 years ago
Is there an elegant solution?
On my CONTROLLER
$request->merge(['id' => $id]); // <---------
$user = (new QueryBuilder(new User(), $request))->build()->get();
On UriParser.php
public function __construct(Request $request) {
$this->request = $request;
$this->uri = $request->getRequestUri();
// ******** Simulate /users/{id} ==> /users?id={id}
// check if exists "id" on $request and "id" not exists on original query string
if ($request->input('id') <> NULL && ! strstr($this->uri, '&id=') && ! strstr($this->uri, '?id='))
{
// position of "id" on query string
if ($this->uri == NULL)
$this->uri = '?id=' . $request->input('id');
else
$this->uri .= '&id=' . $request->input('id');
}
// ***** END
$this->setQueryUri($this->uri);
if ($this->hasQueryUri())
{
$this->setQueryParameters($this->queryUri);
}
}
@robsontenorio Actually, I made this package to easier "index" queries. So, unfortunately this package does not support this feature.
No problem. :) You can close this issue, if you wont work on it.
I use your package for restfull API. So it makes sense (in my case) to have a "hook" for /resource/{id}, that is superpowred by your package.
@robsontenorio
Then, I will examine it on my first free time. Also, if you can solve this issue before me please send a pull request :)
It has solved by #15
Nice lib! Thanks :)
Can i get it by using a rest resource like "/users/{id}" instead of "/users?id={id}"?