|
7 | 7 | - [URLs for Named Routes](#urls-for-named-routes)
|
8 | 8 | - [Signed URLs](#signed-urls)
|
9 | 9 | - [URLs for Controller Actions](#urls-for-controller-actions)
|
| 10 | +- [Fluent URI Objects](#fluent-uri-objects) |
10 | 11 | - [Default Values](#default-values)
|
11 | 12 |
|
12 | 13 | <a name="introduction"></a>
|
@@ -239,6 +240,47 @@ If the controller method accepts route parameters, you may pass an associative a
|
239 | 240 | $url = action([UserController::class, 'profile'], ['id' => 1]);
|
240 | 241 | ```
|
241 | 242 |
|
| 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 | + |
242 | 284 | <a name="default-values"></a>
|
243 | 285 | ## Default Values
|
244 | 286 |
|
|
0 commit comments