You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/1-essentials/01-routing.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,6 +103,24 @@ final class Aircraft implements Bindable
103
103
}
104
104
```
105
105
106
+
By default, `Bindable` objects will be cast to strings when they are passed into the `uri()` function as a route parameter. You can override this default behaviour by tagging a public property on the object with the {b`\Tempest\Router\IsBindingValue`} attribute:
107
+
108
+
```php
109
+
use Tempest\Router\Bindable;
110
+
use Tempest\Router\IsBindingValue;
111
+
112
+
final class Aircraft implements Bindable
113
+
{
114
+
#[IsBindingValue]
115
+
public string $callSign;
116
+
117
+
public function resolve(string $input): self
118
+
{
119
+
return self::find(id: $input);
120
+
}
121
+
}
122
+
```
123
+
106
124
### Backed enum binding
107
125
108
126
You may inject string-backed enumerations to controller actions. Tempest will try to map the corresponding parameter from the URI to an instance of that enum using the [`tryFrom`](https://www.php.net/manual/en/backedenum.tryfrom.php) enum method.
0 commit comments