Skip to content

Commit 509ebaa

Browse files
committed
add fluent uri docs to url page
1 parent 0bcc79f commit 509ebaa

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

urls.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [URLs for Named Routes](#urls-for-named-routes)
88
- [Signed URLs](#signed-urls)
99
- [URLs for Controller Actions](#urls-for-controller-actions)
10+
- [Fluent URI Objects](#fluent-uri-objects)
1011
- [Default Values](#default-values)
1112

1213
<a name="introduction"></a>
@@ -239,6 +240,47 @@ If the controller method accepts route parameters, you may pass an associative a
239240
$url = action([UserController::class, 'profile'], ['id' => 1]);
240241
```
241242

243+
<a name="fluent-uri-objects"></a>
244+
## Fluent URI Objects
245+
246+
Laravel's `Uri` class provides a convenient and fluent interface for creating and manipulating URIs via objects. This class wraps the functionality provided by the underlying League URI package and integrates seamlessly with Laravel's routing system.
247+
248+
You can create a `Uri` instance easily using static methods:
249+
250+
```php
251+
use App\Http\Controllers\UserController;
252+
use App\Http\Controllers\InvokableController;
253+
use Illuminate\Support\Uri;
254+
255+
// Generate a URI instance from the given string...
256+
$uri = Uri::of('https://example.com/path');
257+
258+
// Generate URI instances to paths, named routes, or controller actions...
259+
$uri = Uri::to('/dashboard');
260+
$uri = Uri::route('users.show', ['user' => 1]);
261+
$uri = Uri::signedRoute('users.show', ['user' => 1]);
262+
$uri = Uri::temporarySignedRoute('user.index', now()->addMinutes(5));
263+
$uri = Uri::action([UserController::class, 'index']);
264+
$uri = Uri::action(InvokableController::class);
265+
266+
// Generate a URI instance from the current request URL...
267+
$uri = $request->uri();
268+
```
269+
270+
Once you have a URI instance, you can fluently modify it:
271+
272+
```php
273+
$uri = Uri::of('https://example.com')
274+
->withScheme('http')
275+
->withHost('test.com')
276+
->withPort(8000)
277+
->withPath('/users')
278+
->withQuery(['page' => 2])
279+
->withFragment('section-1');
280+
```
281+
282+
For more information on working with fluent URI objects, consult the [URI documentation](/docs/{{version}}/helpers#uris).
283+
242284
<a name="default-values"></a>
243285
## Default Values
244286

0 commit comments

Comments
 (0)