Download the PHP package phaza/single-table-inheritance without Composer

On this page you can find all versions of the php package phaza/single-table-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 single-table-inheritance

Single Table Inheritance

Credit

This code is a fork of Nanigans/single-table-inheritance. I've only updated it to work with Laravel 5

Latest Stable Version Total Downloads Latest Unstable Version License

Single Table Inheritance is a trait for Laravel 5.0.6+ Eloquent models that allows multiple models to be stored in the same database table. We support a few key featres

Installation

Simply add the package to your composer.json file and run composer update.

Or go to your project directory where the composer.json file is located and type:

Overview

Getting started with the Single Tabe Inheritance Trait is simple. Add the constraint and add a few properties to your models. A complete example of a Vehicle super class with two subclasses Truck and Car is given by

There are four requred properties to be defined in your classes:

Define the database table

In the root model set the protected property $table to define which database table to use to store all your classes.
Note: even if you are using the default for the root class (i.e. the 'vehicles' table for the Vehicle class) this is required so that subclasses inherit the same setting rather than defaulting to their own table name.

Define the databse column to store the class type

In the root model set the protected static proerty $singleTableTypeField to define which database column to use to store the type of each class.

Define the subclasses

In the root model and each branch model define the protected static property $singleTableSubclasses to define which subclasses are part of the classes hierarchy.

Define the values for class type

In each concrete class set the protected static property $singleTableType to define the string value for this class that will be stored in the $singleTableTypeField database column.

Multi Level Class Hierarchies

It's not uncommon to have many levels in your class hierarchy. Its easy to define that structure by declaring subclasses at each level. For example suppose you have a Vehicle super class with two subclasses Bike and MotorVehicle. MotorVehicle in trun has two subclasses Car and Truck. You would define the classes like this:

Defining Which Atttributes Are Persisted

Eloquent is extremly lenient in allowing you to get and set attributes. There is no mechanism to declare the set of attributes that a model supports. If you misues and attribute it typically results in a SQL error if you try to issue an insert or update for a column that doesn't exist. By default the SingleTableInheritanceTrait opperates the same way. However, when storing a class hierarchy in a single table there are often database columns that don't apply to all classes in the heirarchy. That Eloquent will store values in those columns makes it considerably easier to write bugs. There, the SingleTableInheritanceTrait allows you to define which attributes are persisted. The set of persisted attributes is also inherited from parent classes.

In the above example the class Vehicle would persiste the attribute color and the class MotorVehicle would persiste both color and fuel.

Automatically Persisted Attributes

For convineience the model primary key and any dates are automatically added to the list of persisted attributes.

BelongsTo Relations

If you are restricting the persisted attribute and yoru model has BelongsTo relations then you must include the foreign key column of the BelongsTo relation. For example:

Unfortunately there is no efficient way to automatically detect BelongsTo foreign keys.

Throwing Exceptions for Invalid Attributes

BY default the SingleTableINheritanceTrait will handle invalid attributes silently It ignores non-persisted attributes when a model is saved and ignores non-persisted columns when hydrating a model from a builder query. However, you can force exceptions to be thrown when invalid attributes are encounted in either situation by setting the $throwInvalidAttributeExceptions property to true.


All versions of single-table-inheritance with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
illuminate/database Version ~5.0
illuminate/support Version ~5.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 phaza/single-table-inheritance contains the following files

Loading the files please wait ....