Download the PHP package calebporzio/parental without Composer

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

Parental

Parental is a Laravel package that brings STI (Single Table Inheritance) capabilities to Eloquent.

What is single table inheritance (STI)?

It's a fancy name for a simple concept: Extending a model (usually to add specific behavior), but referencing the same table.

Installation

Simple Usage

What problem did we just solve?

Without Parental, calling Admin::first() would throw an error because Laravel would be looking for an admins table. Laravel generates expected table names, as well as foreign keys and pivot table names, using the model's class name. By adding the HasParent trait to the Admin model, Laravel will now reference the parent model's class name users.

Accessing Child Models from Parents

What problem did we just solve?

Before, if we ran: User::first() we would only get back User models. By adding the HasChildren trait and a type column to the users table, running User::first() will return an instance of the child model (Admin or Guest in this case).

Type Aliases

If you don't want to store raw class names in the type column, you can override them using the $childTypes property.

Now, running Admin::create() will set the type column in the users table to admin instead of App\Models\Admin.

This feature is useful if you are working with an existing type column, or if you want to decouple application details from your database.

Custom Type Column Name

You can override the default type column by setting the $childColumn property on the parent model.

Transforming Models Between Types

You may transform a model from one type to another using the become() method.

What problem did we just solve?

The become() method will return a new instance of the specified child model with all the attributes of the original model. You must call save() on the returned model to persist the change to the database. This allows you to easily transition a model between different types while maintaining its data integrity, such as changing an order from pending to shipped, or a draft post to a published post.

This is also useful when you're using observers or callbacks, since the specific child model's behavior will be triggered after the transition.

A new model event is fired when a model is becoming another type, you may listen to it like so:

Eager Loading Child Models

[!WARNING] Eager-loading relationships is only supported on Laravel 11 and above.

To help with eager-loading relationships on child models, Parental provides a set of helpers that you may use in your queries. For the examples, we'll use the following models:

Eager Loading From Model Instance

You may eager-load relationships of different models from a parent model instance using the loadChildren method:

This will ensure that, if $message is an instance of TextMessage, the mentions relationship will be eager-loaded. If it's an instance of ImageMessage, the attachments relationship will be eager-loaded.

Alternatively, you may eager-load the relationship counts using the loadChildrenCount method:

This will ensure that, if $message is an instance of TextMessage, the mentions_count attribute will be filled. If it's an instance of ImageMessage, the attachments_count attribute will be filled.

Eager Loading From Eloquent Collection

You may eager-load relationships from an Eloquent Collection using the loadChildren method:

This will ensure that the appropriate relationships are eager-loaded for each child model in the collection based on its type.

Alternatively, you may eager-load the relationship counts using the loadChildrenCount method:

This will ensure the mentions_count attribute will be filled for instances of the TextMessage model, and the attachments_count attribute will be filled for instances of the ImageMessage model.

Eager Loading From Query and Relationship

You may eager-load relationships directly from a query or relationship using the childrenWith method:

You may also eager-load from a relationship. For instance, if we had a Room parent model that had messages:

Then, we could eager-load child relationships like so:

This will ensure that the appropriate relationships are eager-loaded for each child model in the result set based on its type.

Alternatively, you may eager-load the relationship counts using the childrenWithCount method:

This will ensure the mentions_count attribute is filled on instances of the TextMessage model, and the attachments_count attribute is filled on instances of the ImageMessage model.

Laravel Nova Support

If you want to use share parent Nova resources with child models, you may register the following provider at the end of the boot method of your NovaServiceProvider:


Thanks to @sschoger for the sick logo design, and @DanielCoulbourne for helping brainstorm the idea on Twenty Percent Time.


All versions of parental with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/database Version ^10.0||^11.0||^12.0||^13.0
illuminate/events Version ^10.0||^11.0||^12.0||^13.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 calebporzio/parental contains the following files

Loading the files please wait ...