Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

/users/{id} #11

Closed
robsontenorio opened this issue Nov 24, 2016 · 5 comments
Closed

/users/{id} #11

robsontenorio opened this issue Nov 24, 2016 · 5 comments

Comments

@robsontenorio
Copy link

robsontenorio commented Nov 24, 2016

Nice lib! Thanks :)

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

@robsontenorio
Copy link
Author

robsontenorio commented Nov 26, 2016

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
Copy link
Owner

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

@robsontenorio
Copy link
Author

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
Copy link
Owner

@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
Copy link
Author

It has solved by #15

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants