mirror of
https://github.com/nullthoughts/laravel-data-sync.git
synced 2026-01-26 03:34:02 +00:00
d6d5a4b448ff8df8f6fcbbcc13bdeb564f960da6
Laravel Data Sync
Laravel utility to keep records synced between enviroments through source control
- Add new
syncdisk inconfig/filesystems.php - 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:
[
{
"name": "Ferris Bueller",
"properties->title": "Leisure Consultant",
"phone_numbers->mobile": "555-555-5555",
"phone_numbers->office": "",
"_email": "ferris@buellerandco.com",
"department": {
"name": "Management",
"location": {
"name": "Chicago"
}
}
}
]
translates to:
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,
]);
Notes
- empty values are skipped
- the criteria/attributes for updateOrCreate are identified with a preleading underscore
- nested values represent relationships and are returned using where($key, $value)->first()->id
Languages
PHP
100%