Download the PHP package dive-be/eloquent-super without Composer

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

πŸ¦ΈπŸΌβ€β™‚οΈ - Eloquent Super

Lightweight MTI (Multiple Table Inheritance) support for Eloquent models.

Latest Version on Packagist Total Downloads

What is "Multiple Table Inheritance" exactly?

MTI allows one to have separate database tables for each "sub class" that shares a common "super class".

"Can't I just define a type column in my table and call it a day?"

Well, it depends. If the only thing you'd like to do is adding specific behavior to each sub type (user - admin for example), then Single Table Inheritance is definitely the better choice here.

However, if the sub types have very different data fields, then MTI is the better tool. Using STI in this case will cause the table in question to have a lot of NULL columns.

What problem does this package solve?

Short answer

As a matter of fact, it solves absolutely nothing. "Why this package, then?" you may ask. Well, read on.

Long answer

You see, Eloquent already gives us the ability to define polymorphic relationships. The only thing you need to start leveraging MTI capabilities in Eloquent is a MorphOne relationship. This package adds a nice DX layer on top of the existing functionality, so it is a tad nicer to work with these kind of tightly coupled relationships.

So, the "meat and potatoes" of this package is delegating calls to the defined super relationship (and a couple more things). There is no real "parent" class in an object oriented sense. It is a conscious decision to not sprinkle too much magic on the models.

Installation

Usage

Super / parent class πŸ‘±πŸ»β€β™‚οΈ

Migrations

The super model should define a morphs relationship that follows Laravel's naming conventions: the model's singular name in snake case + able.

Class definition

The super class must define a fillable array in order to determine which attributes belong to which database tables. Without it, there is no way to distinguish the super's columns from the sub's columns.

Sub / child classes πŸ‘ΆπŸΌ

It is not mandatory for the sub classes to define a fillable array. Setting $guarded to an empty array is perfectly fine as well.

Class definition

Capabilities πŸ’ͺ

Partitioning of data when saving a sub model

Attribute / relationship retrieval from super model

Deleting the super along with the sub model

Note: only the sub model will be trashed if both the super and sub use the "SoftDeletes" trait

A note on always eager loading the "super" relationship πŸ“£

It does not make sense for the sub model to exist without its complementary data from the super model. By having two tables, we are able to achieve a normalized database, but in code, it only makes sense when they coexist as a whole.

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of eloquent-super with dependencies

PHP Build Version
Package Version
Requires php Version ~8.3
illuminate/database Version ^11.0
illuminate/support Version ^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 dive-be/eloquent-super contains the following files

Loading the files please wait ....