Copied!

A MorphMany class to mimic Eloquent MorphMany.

Requirements:

The morphing records needs two fields: an integer related key and a string field type long enough to hold the table name of the relationship. They should both be prefixed with the morph field prefix passed into the class. The related key field should follow the same id naming conventions as the rest of the database.

In the Record class definition, you need to define a virtual field with the name of the MorphMany relationship. The key of the virtual field is the member name and the value is an array.

The values in the array should be \PHPFUI\ORM\MorphMany::class, followed by the morphing table class name, then morph field prefix. Sort field and sort order are optional fields.

Example:

protected static array $virtualFields = [
  'images' => [\PHPFUI\ORM\MorphToMany::class, \Tests\App\Table\Image::class, 'imageable', ],
];
CloneableInstantiable
Methods
public PHPFUI\ORM\VirtualField::__construct(PHPFUI\ORM\Record $currentRecord, string $fieldName)
public getValue(array $parameters) : PHPFUI\ORM\RecordCursor
 
  • param string[] $parameters morphing table class name, morph field prefix, optional sort column, optional sort order.
public setValue(?mixed $value, array $parameters) : void
 
  • param mixed $value to add as morph relation for the current record
  • param string[] $parameters morphing table class name, morph field prefix, optional sort column, optional sort order
Properties
protected PHPFUI\ORM\Record PHPFUI\ORM\VirtualField::$currentRecord
protected string PHPFUI\ORM\VirtualField::$fieldName
© 2025 Bruce Wells
Search Namespaces \ Classes
Configuration