Download the PHP package shopapps/has-table-relation without Composer

On this page you can find all versions of the php package shopapps/has-table-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 has-table-relation

HasTable and BelongsToTable relationships for Laravel Eloquent

Provides a relation to an entire table without the need for any linked foreign key attributes.

This package provides a way to link a model to an entire table without the need for any foreign key attributes. This is useful when you have a table that contains data that should be related to a model but does not have a foreign key column to link it to.

Whilst it is always recommend to have a local_key <=> foreign_key mapping (e.g. numbers.customer_id <=> customer.id) for any related data which allows for the standard hasMany / belongsTo relationship(s), sometimes you just inherit data and don't have the luxury of properly designed data models. :-(

NOTE: before usign this package, you could also consider using a belongsToMany relationship and create a pivot table between the two tables. Make sure if you do that you then seed the pivot table mapping all the records you need and also keep them in sync when your code add's removes records. I have added a sample migration file at the bottom of this readme that would allow you to do this as per my customer -> numbers example scenario.

installation

HasTable relationship

Example

In this example the given Customer Model has all the records in the numbers table related to it. Normally you would expect to see a related foreign key column such as customer_id in the numbers table to achieve this and use a hasMany relationship, however in my data this does not exist and due to the sensitive nature of the data I cannot add an extra column to this table.

You can now retrieve all records from the numbers table using:

BelongsToTable relationship

Example

The inverse of the hasTable relationship.

In this example all records in the numbers table belong to the given Customer model. Normally you would expect to see a related local key column such as customer_id in the numbers table to achieve this and use a belongsTo relationship, however in my data this does not exist and due to the sensitive nature of the data I cannot add an extra column to this table.

you can pass an optional second parameter to the belongsToTable method to specify the method to call on the parent model. The default is first but you can also use last or all to call the corresponding method on the parent model query.

You can now retrieve the parent record from any of the the number records using:

BelongsToMany - A laravel standard relationship

Before usign this package, you could also consider using a belongsToMany relationship and create a pivot table between the two tables. Make sure if you do that you then seed the pivot table mapping all the records you need. I have added a sample migration file below that would do this as per my customer -> numbers example scenario.


All versions of has-table-relation with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3|^8.0
illuminate/database Version ^8.0|^9.0|^10.0|^11.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 shopapps/has-table-relation contains the following files

Loading the files please wait ....