Skip to content

Commit 4fb3d91

Browse files
committed
document uri helper
1 parent 340d60f commit 4fb3d91

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

helpers.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Laravel includes a variety of global "helper" PHP functions. Many of these funct
144144
[secure_asset](#method-secure-asset)
145145
[secure_url](#method-secure-url)
146146
[to_route](#method-to-route)
147+
[uri](#method-uri)
147148
[url](#method-url)
148149

149150
</div>
@@ -1921,6 +1922,39 @@ If necessary, you may pass the HTTP status code that should be assigned to the r
19211922
return to_route('users.show', ['user' => 1], 302, ['X-Framework' => 'Laravel']);
19221923
```
19231924

1925+
<a name="method-uri"></a>
1926+
#### `uri()` {.collection-method}
1927+
1928+
The `uri` function generates a [fluent URI instance](#uri) for the given URI:
1929+
1930+
```php
1931+
$uri = uri('https://example.com')
1932+
->withPath('/users')
1933+
->withQuery(['page' => 1])
1934+
```
1935+
1936+
If the `uri` function is given an array containing a callable controller and method pair, the function will create a `Uri` instance for the controller method's route path:
1937+
1938+
```php
1939+
use App\Http\Controllers\UserController;
1940+
1941+
$uri = uri([UserController::class, 'show'], ['user' => $user])
1942+
```
1943+
1944+
If the controller is invokable, you may simply provide the controller class name:
1945+
1946+
```php
1947+
use App\Http\Controllers\UserIndexController;
1948+
1949+
$uri = uri(UserIndexController::class);
1950+
```
1951+
1952+
If the value given to the `uri` function matches the name of a [named route](/docs/{{version}}/routing#named-routes), a `Uri` instance will be generated for that route's path:
1953+
1954+
```php
1955+
$uri = uri('users.show', ['user' => $user]);
1956+
```
1957+
19241958
<a name="method-url"></a>
19251959
#### `url()` {.collection-method}
19261960

0 commit comments

Comments
 (0)