Download the PHP package asseco-voice/laravel-remote-relations without Composer

On this page you can find all versions of the php package asseco-voice/laravel-remote-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 laravel-remote-relations

Laravel remote relations

This package enables creating relations locally from Eloquent models to remote services.

Installation

Install the package through composer. It is automatically registered as a Laravel service provider, so no additional actions are required.

composer require asseco-voice/laravel-remote-relations

Setup

  1. Run php artisan migrate to migrate the table.

Table consists of:

  1. Local model type/id - polymorphic relation of local Eloquent models
  2. Service - indicating a key which needs to be mapped to a certain service class
  3. Remote model - plain string representing a model in a remote service (isn't Laravel specific)
  4. Remote model ID - actual ID to which a relation is created
  5. Acknowledged - date to verify if reverse relation was created

Out of the box no services are registered because the package doesn't know where to fetch related data from, so you need to provide services manually.

  1. Publish the configuration with php artisan vendor:publish --tag=asseco-remote-relations-config
  2. Create a new service class for remote service you'd like to make a relation to and make it extend HasRemoteRelations interface
  3. Interface has 2 methods which are responsible for resolving a single relation or a collection of relations.
  4. Resolving collections will always be done on a single model type (i.e. collection of users) on a single service so that you can resolve multiple models at once if possible.
  5. Model IDs are of string type so that it supports non-numeric IDs as well.
  6. Add the class to config under services key in the format 'service_name' => Service::class'

Usage

Have your models use a Relatable trait which will provide an Eloquent relation to a RemoteRelation class, so you don't have to repeat yourself.

There are also several handy methods:

CRUD API

Standard API resource is published on api/remote-relations endpoint with standard CRUD routes.

Going on api/remote-relations/many, you can execute a POST request to store many relations at once.

Additionally, there is a GET api/remote-relations/{remote_relation}/resolved endpoint which will return a resolved relation.

Acknowledgement

Initially when you create a remote relation from service A to service B, acknowledged attribute is null. When service B catches the event and creates the relation in its database, it should set the acknowledged attribute of a newly created row to true and communicate back to service A to set acknowledged attribute of original relation to now().

Resolving relations programmatically

You will probably want to have a class which knows how to resolve particular relations. To do that, have your SDK class implement a HasRemoteRelations interface and implement methods from it.

Once you do that, register that class in services.php under sdk key. Service name must be the name which you are storing in the DB when populating the service attribute.

Example

Given the following configuration in services.php:

Having added a Relatable trait to your User model.

You can now call a relate() method on a single user instance like this:

Note that first parameter equals to the service key in the configuration. That is how package knows which service to use.

Resolving relations can be done for a single relation, or a collection of relations:

Extending the package

Publishing the configuration will enable you to change package models as well as controlling how migrations behave. If extending the model, make sure you're extending the original model in your implementation.


All versions of laravel-remote-relations with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
laravel/framework Version ^10.0
asseco-voice/laravel-common Version ^3.0
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 asseco-voice/laravel-remote-relations contains the following files

Loading the files please wait ....