This package provides a better support for MongoDB relationships in Laravel Projects.
offline-agency/laravel-mongo-auto-sync is a Laravel package for this package provides a better support for mongodb relationships in laravel projects..
It currently has 16 GitHub stars and 480 downloads on Packagist (latest version 3.1.1).
Install it with composer require offline-agency/laravel-mongo-auto-sync.
Discover more Laravel packages by offline-agency
or browse all Laravel packages to compare alternatives.
Last updated
This package provides a better support for MongoDB relationships in Laravel Projects. At low level all CRUD operations has been handled by jenssegers/laravel-mongodb
composer require offline-agency/laravel-mongo-auto-sync
Make sure you have the MongoDB PHP driver installed. You can find installation instructions at http://php.net/manual/en/mongodb.installation.php
| This package | Laravel | Laravel MongoDB | |--------------|---------|-----------------| | 1.x | 5.8.x | 3.5.x | | 1.x | 6.x | 3.6.x | | 2.x | 5.8.x | 3.5.x | | 2.x | 6.x | 3.6.x | | 2.x | 7.x | 3.7.x | | 2.x | 8.x | 3.8.x | | 2.x | 9.x | 3.9.x | | 3.x | 5.8.x | 3.5.x | | 3.x | 6.x | 3.6.x | | 3.x | 7.x | 3.7.x | | 3.x | 8.x | 3.8.x | | 3.x | 9.x | 3.9.x |
//create a new Article with title "Game of Thrones" with Category "TV Series"
//assign data to $article
$article->save();
/*
Article::class {
'title' => 'Game of Thrones',
'category' => Category::class {
'name' => 'TV Series'
}
}
*/
//Retrieve 'TV Series' category
$category = Category::where('name', 'TV Series')->first();
/*
Category::class {
'name' => 'Game of Thrones',
'articles' => null
}
*/
The sub document article has not been updated with the new article. So you will need some extra code to write in order to see the new article it in the category page. The number of sync depends on the number of the relationships and on the number of the entry in every single EmbedsMany relationships.
Total updates = ∑ (entry in all EmbedsMany relationships) + ∑ (EmbedsOne relationships)
As you can see the lines of extra code can rapidly increase, and you will write many redundant code.
//create a new Article with title "Game of Thrones" with Category "TV Series"
$article->storeWithSync($request);
/*
Article::class {
'title' => 'Game of Thrones',
'category' => Category::class {
'name' => 'TV Series'
}
}
*/
//Retrieve 'TV Series' category
$category = Category::where('name', 'TV Series')->first();
/*
Category::class {
'name' => 'Game of Thrones',
'articles' => Article::class {
'title' => 'Game of Thrones'
}
}
*/
The sub document article has been updated with the new article, with no need of extra code :tada:
You can see the new article on the category page because the package synchronizes the information for you by reading the Model Setup.
These example can be applied for all write operations on the database.
You can find the documentation here
Run this command inside your project's route
docker-compose up
Now run the tests with:
composer test
Please see CONTRIBUTING for details.
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
Offline Agency is a web design agency based in Padua, Italy. You'll find an overview of our projects on our website.
The MIT License (MIT). Please see License File for more information.