selahattinunlu / laravel-api-query-builder

Laravel & Lumen Api Query Builder Package
331 stars 66 forks source link

/users/{id} #11

Closed robsontenorio closed 7 years ago

robsontenorio commented 7 years ago

Nice lib! Thanks :)

Can i get it by using a rest resource like "/users/{id}" instead of "/users?id={id}"?

robsontenorio commented 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);
        }
}
selahattinunlu commented 7 years ago

@robsontenorio Actually, I made this package to easier "index" queries. So, unfortunately this package does not support this feature.

robsontenorio commented 7 years ago

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.

selahattinunlu commented 7 years ago

@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 :)

robsontenorio commented 7 years ago

It has solved by #15