Download the PHP package amethyst/relation-schema without Composer

On this page you can find all versions of the php package amethyst/relation-schema. 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 relation-schema

Relation Schema

Action Status Amethyst

Create your own custom relations between Eloquent Models without altering the code.

Requirements

Installation

You can install it via Composer by typing the following command:

The package will automatically register itself.

Initialization

Add app('amethyst.relation-schema')->boot(); in any ServiceProvider in the method boot

Usage

A simple usage looks like this

Here's a list of all attributes with a brief explanation:

Whenever refering to any model, we will call it by name. For e.g. \App\Models\Customer will be customer. More info

Keep in mind that this is an Amethyst Package, if you wish to see the full list of available features and customization please check core

Relationships

As said before, based on the type attribute, payload must have a different sets of value. It uses Yaml for the serialization, so for all examples we will use a Symfony\Component\Yaml\Yaml to convert from array to Yaml.

Most of relation uses the laravel-defined convention of names, such as foreignKey or ownerKey.

BelongsTo

Starting with the most simple relation, BelongsTo. It requires only the target parameter that indicate to which Model we are relating.

You can also set the foreignKey option.

So for example this new record

is the exact same thing like this

HasMany and HasOne

The inverse relationship of BelongsTo. They behave exactly the same.

Beside the target you can set foreignKey and localKey.

Now let's look an example of the same relationship in BelongsTo but inverted

Will result in:

But wait, there's more! You can create relations with a custom subfilter. Say for example that having a customer and invoice you want to create a relation that retrieve all invoices with status:paid from your customer.

You can add another parameter called filter in the payload.

So having something like this: filter: "status eq 'paid'". You can also use auto joins here, so for e.g. a query like: only the invoice that contains Maintenance in the name, will result in filter: "status eq 'paid' and items.name ct 'Maintenance'".

Limitation: You cannot insert in the filter the same relation you're currently defining

ManyToMany and BelongsToMany

Not yet implemented.

MorphTo

Similar toBelongsTo it doesn't require a target, instead it requires a foreignKey that in this case means the name of the field

MorphToMany and MorphToOne

WIP

MorphMany

WIP

Api

There are no additional routes in this package, only the default provided by the core.

Testing


All versions of relation-schema with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
amethyst/core Version 0.3.*
amethyst/relation Version 0.3.*
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 amethyst/relation-schema contains the following files

Loading the files please wait ....