Skip to content

Commit

Permalink
Add URL::query() method documentation (#9598)
Browse files Browse the repository at this point in the history
* Add url()->query() method documentation

* Fix typo

* Update urls.md

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
stevebauman and taylorotwell authored Apr 25, 2024
1 parent 50d6c95 commit 387f697
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions urls.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,32 @@ The `url` helper may be used to generate arbitrary URLs for your application. Th

// http://example.com/posts/1

To generate a URL with query string parameters, you may use the `query` method:

echo url()->query('/posts', ['search' => 'Laravel']);

// https://example.com/posts?search=Laravel

echo url()->query('/posts?sort=latest', ['search' => 'Laravel']);

// http://example.com/posts?sort=latest&search=Laravel

Providing query string parameters that already exist in the path will overwrite their existing value:

echo url()->query('/posts?sort=latest', ['sort' => 'oldest']);

// http://example.com/posts?sort=oldest

Arrays of values may also be passed as query parameters. These values will be properly keyed and encoded in the generated URL:

echo $url = url()->query('/posts', ['columns' => ['title', 'body']]);

// http://example.com/posts?columns%5B0%5D=title&columns%5B1%5D=body

echo urldecode($url);

// http://example.com/posts?columns[0]=title&columns[1]=body

<a name="accessing-the-current-url"></a>
### Accessing the Current URL

Expand Down

1 comment on commit 387f697

@bornemisza
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taylorotwell Ran into an issue here. Illuminate\Contracts\Routing\UrlGenerator does not implement query() at the moment on 11.x.

Please sign in to comment.