Download the PHP package culturegr/custom-relation without Composer

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

🏺 Custom Relation

Latest Version on Packagist Total Downloads Github Actions

This package provides an easy way to implement custom relationships between Eloquent models

Installation

Via Composer:

In Laravel 5.5+, the package's service provider should be auto-discovered, so you won't need to register it. If for some reason you need to register it manually you can do so by adding it to the providers array in config/app.php:

Usage

Suppose we have a Laravel application that implements a simple ACL (Access Control List) layer: there are users that are assigned some roles, each of them consists of many permissions. A simplified version of the database structure could be the following:

Alt text

There is a User model that has a many-to-many relationship with a Role model, which in turn has a many-to-many relationship with a Permission model.

Now suppose that at some point, we need to access all permissions assigned to a specific user. Let's make this possible by creating a CustomRelation class that will be used to define the relationship between the User and the Permission models.

Creating a Custom Relation Class

A CustomRelation class should facilitate all required logic needed to join users and permissions tables, as well as to support relationship eager-loading. It can be created by running the make:relation Artisan command:

This will generate a new CustomRelation class named UserPermissionRelation inside app/Eloquent/CustomRelations directory with all required boilerplate:

Implementing the Custom Relation Class

The UserPermissionRelation class initializes two properties:

In order to define the users/permissions relationship, the following methods should be implemented:

addConstraints

Sets the base constraints on the relation query. In our example:

addEagerConstraints

Sets the constraints for an eager load of the relation. In our example:

match

Matches the eagerly loaded results to their parents. In our example:

Using the Custom Relation Class

Once the UserPermissionRelation class has been implemented, it can be used to define a new custom relationship between the User and the Permission model via relatesTo method which is available to the model through HasCustomRelation trait:

That's it 🔥! Now we can use our new custom permissions relationship like any usual Eloquent relationship:

Testing

License

Please see the license file for more information.

Credits


All versions of custom-relation with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0|^8.1
illuminate/support Version ^8.0|^9.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 culturegr/custom-relation contains the following files

Loading the files please wait ....