Skip to content

Commit 0c6ea31

Browse files
committed
Add example
1 parent 26ab964 commit 0c6ea31

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

readme.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,42 @@ Laravel utility to keep records synced between enviroments through source contro
66
- Create a JSON file for each model, using the model name as the filename. Example: Product.json would update the Product model
77
- Use nested arrays in place of hardcoded IDs for relationships
88
- Run `php artisan data:sync`
9+
10+
11+
## Examples
12+
**User.json**:
13+
```json
14+
[
15+
{
16+
"name": "Ferris Bueller",
17+
"properties->title": "Leisure Consultant",
18+
"phone_numbers->mobile": "555-555-5555",
19+
"phone_numbers->office": "", // empty values are skipped
20+
"_email": "[email protected]", // the criteria/attributes for updateOrCreate are identified with a preleading underscore
21+
"department": { // nested values represent relationships and are returned using where($key, $value)->first()
22+
"name": "Management",
23+
"location": {
24+
"name": "Chicago"
25+
}
26+
}
27+
}
28+
]
29+
```
30+
31+
translates to:
32+
33+
```php
34+
35+
User::updateOrCreate([
36+
'email' => '[email protected]',
37+
],[
38+
'name': 'Ferris Bueller',
39+
'properties->title' => 'Leisure Consultant',
40+
'phone_numbers->mobile' => '555-555-5555',
41+
'department_id' => Department::where('name', 'Management)
42+
->where('location_id', Location::where('name', 'Chicago')->first()->id)
43+
->first()
44+
->id,
45+
]);
46+
47+
```

0 commit comments

Comments
 (0)