- What does mathieutu/laravel-json-syncer actually do in a Laravel app?
- It is a small, single-purpose importer/exporter that keeps JSON columns in sync with regular database columns. Values stored inside JSON attributes, such as translations, get mirrored into dedicated columns so you can query, sort and index them efficiently. It is trait-based and lightweight, not a full data pipeline.
- How do I install and configure laravel-json-syncer?
- Install it with composer require mathieutu/laravel-json-syncer, pinning ^1.3 rather than dev-master. Package auto-discovery handles the service provider, so setup is usually just adding the trait to the relevant Eloquent models and defining which JSON keys map to which columns. There is no config publish or migration indicated for the 1.2.x to 1.3.x upgrade.
- Which Laravel versions does laravel-json-syncer support?
- Release 1.3.0 is essentially a compatibility release that widens constraints for Laravel 7. The notes contain no mention of Laravel 8+, PHP 8, or a modern CI pipeline, which suggests the support horizon currently ends at Laravel 7. Always confirm the exact illuminate/support and PHP ranges in composer.json before assuming newer framework support.
- Is laravel-json-syncer still actively maintained?
- It has a single maintainer and a low release cadence, and its CI moved from one Travis configuration to another rather than to GitHub Actions. That is a signal to treat the package as having a finite runway. If your application targets Laravel 8 or newer, plan for a fork or replacement rather than expecting an upstream upgrade.
- Does laravel-json-syncer delete database rows that are missing from the JSON file?
- The syncer naming implies reconciliation, which typically means upserts plus removal of records absent from the JSON source, but destructive behaviour is not clearly advertised. Confirm against the source or a staging copy of your data before running it against anything user-authored. For reference data and config tables this behaviour is usually desirable; for production user data it is risky.
- Do model events, observers and casts fire during a JSON sync?
- Yes. The package writes through your Eloquent models, so casts, mutators, $fillable/$guarded rules, validation, model events and observers all execute during the sync. That gives you consistency with normal application writes, but it also means slow observers or side effects such as notifications and audit logging can fire unexpectedly.
- How do I make translated JSON attributes sortable and queryable in Laravel?
- Mirror each translation into a dedicated database column so you can orderBy, filter and index it directly instead of relying on JSON path expressions. This package automates that mirroring through a trait and an artisan sync command. It is a common pattern when working with packages that store translations as JSON, such as spatie/laravel-translatable.
- Is laravel-json-syncer suitable for seeding reference data and config tables?
- That is its best fit: reference-data seeding, config-table synchronisation and environment bootstrapping. It belongs in the operational and data-tooling layer, not in request-path application code. Its footprint is a service provider plus command, so adopting and later removing it are both cheap.
- Can I run laravel-json-syncer in a transaction, with a dry run, or on large files?
- The package does not advertise transactional wrapping, dry-run, --force, environment gating, or chunked streaming of large JSON files. Verify these in the source before relying on them, and if they are missing, wrap the command in DB::transaction or add your own guard clauses. For large datasets, test memory usage first and consider chunking the JSON input yourself.
- What are the alternatives to laravel-json-syncer?
- You can replicate the behaviour with a custom artisan command that uses Eloquent upsert() or updateOrCreate(), or with database seeders for reference data. A hand-rolled sync is more code but gives you explicit control over deletion, transactions, chunking and dry-run behaviour. If you are already past Laravel 7, forking this package with an explicit, reviewable patch is often safer than widening constraints upstream.