# staudenmeir/eloquent-json-relations

Laravel Eloquent relationships with JSON keys

Repository: https://github.com/staudenmeir/eloquent-json-relations
Canonical: https://ross.abutalabs.com/products/eloquent-json-relations
Language: PHP
License: MIT
License Family: permissive
Last push: 2026-07-04T10:00:27+00:00

## Health v2 (maintenance only)
Score: 86/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 90, release rhythm 72, longevity 100
- inputs: {"age_days": 2891, "days_push": 60, "days_rel": 185, "gap_med": 9.5, "n_releases_24m": 7}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 1079, forks 64 (observed 2026-08-28T04:03:30.044354+00:00)

## What it is
A Laravel Eloquent extension that adds support for JSON foreign keys in relationships like BelongsTo, HasOne, HasMany, and morph variants. It also enables many-to-many and has-many-through relationships based on JSON arrays across multiple database engines.

## Use cases
- define eloquent relationships where foreign keys are stored in  columns
- query hasmany relations through a  array of ids in laravel
- build many-to-many relationships using  arrays of objects
- use belongsTo with a foreign key inside a  field
- run -based eloquent relations on mysql, postgres, sqlite, or sql server
- avoid pivot tables by storing related ids in a  column

## When to choose
- you use Laravel Eloquent and store foreign keys or id arrays in JSON columns
- you want relationship support without dedicated pivot tables or columns
- you need cross-database JSON relation support (MySQL, MariaDB, PostgreSQL, SQLite, SQL Server)

## When to avoid
- you don't use Laravel or Eloquent ORM
- your schema uses conventional dedicated foreign key columns
- you need JSON relations on databases outside the supported versions

## Facets
- artifact type: library
- maturity: active
- function: orm, database
- domain: web-development, databases, backend
- platform: php
- tags: eloquent, laravel-package, -relationships, foreign-keys, mysql, postgresql, sqlite, laravel

## Member repositories
- staudenmeir/eloquent-json-relations (main) score 86

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:03:30.044354+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-30T06:53:06.456360+00:00, confidence not recorded.
  - readme: https://github.com/staudenmeir/eloquent-json-relations (fetched 2026-08-28T04:03:30.044354+00:00, sha 9b750bb33674)
- Data as of 2026-08-30T08:39:29.467469+00:00.
