Download the PHP package proai/eloquent-inheritance without Composer

On this page you can find all versions of the php package proai/eloquent-inheritance. 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-inheritance

Eloquent Inheritance

Latest Stable Version Total Downloads Latest Unstable Version License

Single table inheritance is a way to emulate object-oriented inheritance in a relational database. While other frameworks like Ruby on Rails have a built-in implementation for this pattern, Laravel has not. This package aims to provide an as easy as possible implementation for Laravel.

Installation

You can install the package via composer:

Please note that you need at least PHP 8.0 and Laravel 9 for this package.

Usage

First you need to add the Inheritance trait to your root model:

Then you can extend the root model by other models that use the same table:

Note that you need a table pets with a column called type in order to make the example above work.

Whenever a Cat or Dog model is instantiated, the attribute type will be set to the classname of the class (e.g. App\Models\Cat).

Other than that there is no magic and a Cat or a Dog model will behave just like a normal Eloquent model. You can define cat or dog specific attributes and relationships on these models. An attribute only set for dogs for example should be a nullable column on the table, so that it is set for dogs but null for other pets.

Root model behaviour

You can query the root model like any other model. However, the returned models will be transformed based by the type name. For example if there is one cat and one dog in the database, Pet::all(); will return one Dog and one Cat model.

It is not possible to use new Pet($attributes); when you specify the type in $attributes. Please use the static method Pet::new($attributes) instead. This method returns a new model based on the given type. For example if the type in $attributes is App\Models\Cat, it will return an instance of App\Models\Cat. If no type is specified, an instance of App\Models\Pet will be returned.

Custom type names

If you want to use different names for the type column than the classname, you can use the static $inheritanceMap property:

Custom type column

By default the name of the type column is type. However, you can set a custom type column name:

Support

Bugs and feature requests are tracked on GitHub.

License

This package is released under the MIT License.


All versions of eloquent-inheritance with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/support Version ^9.0||^10.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 proai/eloquent-inheritance contains the following files

Loading the files please wait ....