Releases: vildanbina/laravel-model-json
Release list
v2.5
What's Changed
- Fix relationship import by @jakobploens in #12
New Contributors
- @jakobploens made their first contribution in #12
Full Changelog: v2.4...v2.5
v2.4
- Adds support for Laravel 12 #11 @szepeviktor
v2.3
v2.2
v2.1
replace hardcoded backslash with DIRECTORY_SEPARATOR for cross-platform compatibility
Adding a feature to import Models with relationships together
This package introduces a new feature that allows importing models along with their relationships from JSON. The supported relationship types include HasOne, HasMany, HasOneThrough, HasManyThrough, MorphOne, MorphMany, MorphToMany, MorphTo, BelongsTo, and BelongsToMany. You can import models with their relationships using the --with-relationships={relations} option, where {relations} represent the names of the relationships and can be separated by + if you want to attach multiple relationships.
For instance, if you want to import a Category model with its Product relationship, you can use the command:
php artisan model:import Category public/Categories.json --with-relationships=productsIf you want to import a Category model along with both its Product and User relationships, you can use the command:
php artisan model:import Category public/Categories.json --with-relationships=products+userMoreover, you can selectively import columns of the relationship using the syntax {relationship_name}:{columns_to_import}.
For example, if you want to import a Category model along with its Product relationship and only import the id and name columns of the Product, you can use the command:
php artisan model:import Category public/Categories.json --with-relationships=products:id,nameNote: that in addition to the assignment made while importing a product to a category with relationships, the Category model will also be updated with the attributes found in the JSON.
Fix issue on importing
fixing a bug on importing with exsiting keys by modifying the variable name