Download the PHP package elkadrey/eloquent-json-relations without Composer

On this page you can find all versions of the php package elkadrey/eloquent-json-relations. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package eloquent-json-relations

CI Code Coverage Scrutinizer Code Quality Latest Stable Version Total Downloads License

Introduction

This Laravel Eloquent extension adds support for JSON foreign keys to BelongsTo, HasOne, HasMany, HasOneThrough, HasManyThrough, MorphTo, MorphOne and MorphMany relationships.
It also provides many-to-many relationships with JSON arrays.

Compatibility

Database Laravel
MySQL 5.7+ 5.5.29+
MariaDB 10.2+ 5.8+
PostgreSQL 9.3+ 5.5.29+
SQLite 3.18+ 5.6.35+
SQL Server 2016+ 5.6.25+

Installation

composer require "elkadrey/eloquent-json-relations:^1.1"

Use this command if you are in PowerShell on Windows (e.g. in VS Code):

composer require "elkadrey/eloquent-json-relations:^^^^1.1"

Usage

One-To-Many Relationships

In this example, User has a BelongsTo relationship with Locale. There is no dedicated column, but the foreign key (locale_id) is stored as a property in a JSON field (users.options):

Remember to use the HasJsonRelationships trait in both the parent and the related model.

Referential Integrity

On MySQL, MariaDB and SQL Server you can still ensure referential integrity with foreign keys on generated/computed columns.

Laravel migrations support this feature on MySQL/MariaDB:

Laravel migrations (5.7.25+) also support this feature on SQL Server:

There is a workaround for older versions of Laravel.

Many-To-Many Relationships

The package also introduces two new relationship types: BelongsToJson and HasManyJson

On Laravel 5.6.25+, you can use them to implement many-to-many relationships with JSON arrays.

In this example, User has a BelongsToMany relationship with Role. There is no pivot table, but the foreign keys are stored as an array in a JSON field (users.options):

Array of IDs

By default, the relationship stores pivot records as an array of IDs:

On the side of the BelongsToJson relationship, you can use attach(), detach(), sync() and toggle():

Array of Objects

You can also store pivot records as objects with additional attributes:

Here, options->roles is the path to the JSON array. role_id is the name of the foreign key property inside the record object:

Limitations: On SQLite and SQL Server, these relationships only work partially.

Query Performance

On PostgreSQL, you can improve the query performance with jsonb columns and GIN indexes.

Use this migration when the array of IDs/objects is the column itself (e.g. users.role_ids):

Use this migration when the array is nested inside an object (e.g. users.options->role_ids):

Contributing

Please see CODE OF CONDUCT for details.


All versions of eloquent-json-relations with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3|^8.2|^8.1
illuminate/database Version ^9.0|^10|^11|^12
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package elkadrey/eloquent-json-relations contains the following files

Loading the files please wait ....