Skip to content

Commit 34f11e9

Browse files
authored
Merge pull request #70 from Lloople/patch-1
Add documentation for saving attributes
2 parents 7df7da6 + 532f14b commit 34f11e9

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

docs/usage/forms.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,43 @@ $post->fill([
1313
]);
1414
```
1515

16+
## Request as array syntax
17+
1618
To achieve this structure in your form - to prevent manipulating the form data just to save them. You can use the input name array `[]` [syntax](https://www.php.net/manual/en/faq.html.php#faq.html.arrays).
1719

18-
```markup
20+
```html
1921
<input type="text" name="en[title]" />
2022
<input type="text" name="de[title]" />
2123
```
2224

25+
## Request as plain syntax
26+
27+
If you want, you can structure the request inputs in colon notation too. Notice that with this approach the attribute goes first.
28+
29+
```html
30+
<input type="text" name="title:en" />
31+
<input type="text" name="title:de" />
32+
```
33+
34+
## Saving the request
35+
36+
Both ways are ready to save the translatable attributes to the model without any other modification.
37+
38+
```php
39+
public function update(Request $request, Post $post)
40+
{
41+
$post->update($request->all());
42+
}
43+
```
44+
45+
# Updating the default locale
46+
47+
You can update the default locale attributes by accessing the translatable attributes from the model itself.
48+
49+
```php
50+
$post->title = 'My first post'; // Will update the English translatable model
51+
```
52+
53+
```php
54+
$post->fill(['title' => 'My first post']); // Will update the English translatable model
55+
```

0 commit comments

Comments
 (0)