From 0c6ea31894c3fa999f5628531921ef48c439be15 Mon Sep 17 00:00:00 2001 From: distinctm Date: Wed, 23 Jan 2019 13:53:40 -0500 Subject: [PATCH] Add example --- readme.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/readme.md b/readme.md index f25eeb2..221723c 100644 --- a/readme.md +++ b/readme.md @@ -6,3 +6,42 @@ Laravel utility to keep records synced between enviroments through source contro - Create a JSON file for each model, using the model name as the filename. Example: Product.json would update the Product model - Use nested arrays in place of hardcoded IDs for relationships - Run `php artisan data:sync` + + +## Examples +**User.json**: +```json +[ + { + "name": "Ferris Bueller", + "properties->title": "Leisure Consultant", + "phone_numbers->mobile": "555-555-5555", + "phone_numbers->office": "", // empty values are skipped + "_email": "ferris@buellerandco.com", // the criteria/attributes for updateOrCreate are identified with a preleading underscore + "department": { // nested values represent relationships and are returned using where($key, $value)->first() + "name": "Management", + "location": { + "name": "Chicago" + } + } + } +] +``` + +translates to: + +```php + +User::updateOrCreate([ + 'email' => 'ferris@buellerandco.com', +],[ + 'name': 'Ferris Bueller', + 'properties->title' => 'Leisure Consultant', + 'phone_numbers->mobile' => '555-555-5555', + 'department_id' => Department::where('name', 'Management) + ->where('location_id', Location::where('name', 'Chicago')->first()->id) + ->first() + ->id, +]); + +``` \ No newline at end of file