- How do I install Laragear/Json in a Laravel application?
- Install it with Composer via composer require laragear/json. The package is a thin library with no service provider footprint beyond what Laravel auto-discovers, so there is nothing else to boot. Publishing the optional config file is useful if you want to customise defaults, but the package works out of the box. After installing, you change the relevant model $casts entries to the package cast and update any call sites that previously read the attribute as a plain array.
- What PHP and Laravel versions does Laragear/Json require?
- The package targets modern Laravel applications on PHP 8.1 and above. Note that the 4.0.0 release body is only a changelog link and does not explicitly state a minimum PHP or Laravel version, so you should confirm the exact constraints in the package composer.json before bumping. If v4 raises the Laravel floor beyond what your app currently runs, the package upgrade is blocked behind the framework upgrade and must be sequenced after it. Always check the constraints against your app's locked PHP and Laravel versions first.
- What is the difference between Laragear/Json and Laravel's native AsArrayObject cast?
- Laravel's native array and AsArrayObject casts rewrite the entire JSON document whenever the attribute is saved. Laragear/Json instead exposes an object wrapper that lets you read and mutate individual keys and persist only those keys. That makes it valuable when JSON columns are load-bearing and multiple writers touch different keys of the same row. If JSON in your app is incidental, a native array or AsArrayObject cast is usually sufficient and avoids the migration cost.
- How does Laragear/Json update a single key without overwriting the whole JSON column?
- When you call save on the wrapper, the package issues a targeted UPDATE using the database's native JSON function, such as JSON_SET on MySQL, jsonb_set on PostgreSQL, and json_set on SQLite. Only the keys you changed are written, so concurrent writers touching other keys are far less likely to clobber each other. This is the package's main architectural benefit over array casts, which persist the whole document and can silently overwrite another writer's changes.
- Which database engines support Laragear/Json partial JSON updates?
- MySQL 8+ and PostgreSQL 12+ are the safe targets, and SQLite works if the version is recent enough to provide json_set. MariaDB's JSON support is a known gap and should be treated as a blocker until you have proven parity yourself. Because driver parity failures in the partial-update SQL corrupt data rather than throwing an exception, test each engine you deploy on rather than assuming behaviour carries over. Confirm your engine explicitly before adopting the package.
- How do I upgrade Laragear/Json from 3.x to 4.x safely?
- Pin ^3.0 on your current branch and disable automatic major upgrades in Dependabot or Renovate. Then run a time-boxed spike branch on ^4.0: bump the constraint, run the full test suite, and diff the serialized output of one representative model before and after. Derive the real breaking-change list by reading the repository changelog and diffing the public API rather than trusting the release notes. Do not adopt 4.0.0 on release day; wait for 4.0.x patches and set a concrete review date.
- What changed in Laragear/Json 4.0 and is there an upgrade guide?
- Version 4.0.0 is a major bump whose release body is only a link to the changelog, with no explicit breaking-change callout, no migration guide, and no stated minimum PHP or Laravel version. That absence is the primary risk signal, because you cannot scope an upgrade from the release artifact alone. Verify renamed or removed cast and class names, changed return semantics for missing keys, and any change to JsonSerializable output that would silently alter API resource payloads. Check the repository changelog and diff the public API directly.
- Can Laragear/Json validate nested data stored inside a JSON column?
- Yes, validating nested data is one of the package's stated capabilities alongside typed casting and clean querying of values. Casting the attribute to a typed object gives you a stable structure to validate against instead of passing raw arrays around. Keep validation rules close to the cast so the shape enforced at write time matches the shape your code expects at read time. This also keeps Eloquent models tidy by moving JSON handling out of the model body.
- Is Laragear/Json actively maintained and safe to use in production?
- It is community-maintained by a single author, Laragear (Italo Barragan), and is not a first-party Laravel package, which is the dominant architectural caveat rather than any flaw in the code. Support is via community issues with no SLA, and the user base is small enough that upstream regressions are found late. Mitigate by assigning a named internal owner, tracking releases on a quarterly cadence, and keeping a pinned major so an unexpected break cannot reach production. If your organisation needs commercial support, note there is no guaranteed path here.
- What are the alternatives to Laragear/Json for JSON columns in Laravel?
- The main alternative is Laravel's built-in array, AsArrayObject, and AsCollection casts, which are first-party and require no extra dependency but rewrite the whole document on save. You can also write a custom cast tailored to your schema if you only need typed access without partial-key persistence. Laragear/Json is worth its migration cost mainly where JSON columns are load-bearing and concurrent writers touch different keys. Where JSON is incidental, staying with native casts is the lower-risk choice.