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/basic-usage/model-binding.md
+54-32Lines changed: 54 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,40 +3,55 @@ title: Model Binding and Default Values
3
3
sidebar_position: 2
4
4
---
5
5
6
-
You can use the `default` attribute to specify the default value of the element.
6
+
7
+
Model binding allows you to populate your forms with data from Eloquent models or other objects automatically.
8
+
9
+
## Precedence Order
10
+
11
+
It is important to understand how the component decides which value to show. The priority list is as follows (highest to lowest):
12
+
13
+
1.**Old Input**: If a validation error occurred or the form was just submitted, `old('name')` takes top priority.
14
+
2.**Explicit Value**: A hardcoded `:value="..."` attribute.
15
+
3.**Model Binding**: Value derived from a bound Model or Object (e.g., `$user->name`).
16
+
4.**Default Attribute**: The `default="..."` attribute passed to the component.
17
+
5.**Null**: Empty string.
18
+
19
+
## Binding Methods
20
+
21
+
### 1. Simple Default Values
22
+
23
+
For simple use cases where you just want a fallback value:
7
24
8
25
```html
9
26
<x-forms::textareaname="motivation"default="I want to use this package because..." />
10
27
```
11
28
12
-
#Binding a target
29
+
### 2. Binding (Single Component)
13
30
14
-
Instead of setting a default value, you can also pass in a target, like an Eloquent model. Now the component will get the value from the target by the `name`.
31
+
You can bind a specific model to a single component.
0 commit comments