UserFrosting API

HasRelationships

HasRelationships trait.

Extends Laravel's Model class to add some additional relationships.

Tags
author

Alex Weissman (https://alexanderweissman.com)

Table of Contents

$manyMethodsExtended The many to many relationship methods. array
hasMany() Overrides the default Eloquent hasMany relationship to return a HasManySyncable. trait:short
morphMany() Overrides the default Eloquent morphMany relationship to return a MorphManySyncable. trait:short
belongsToManyThrough() Define a many-to-many 'through' relationship. trait:short
belongsToManyUnique() Define a unique many-to-many relationship. Similar to a regular many-to-many relationship, but removes duplicate child objects. trait:short
morphToManyUnique() Define a unique morphs-to-many relationship. Similar to a regular morphs-to-many relationship, but removes duplicate child objects. trait:short
getBelongsToManyCaller() Get the relationship name of the belongs to many. string

Properties

$manyMethodsExtended

The many to many relationship methods.

public static array $manyMethodsExtended = ['belongsToMany', 'morphToMany', 'morphedByMany', 'morphToManyUnique']

Methods

hasMany()

Overrides the default Eloquent hasMany relationship to return a HasManySyncable.

public hasMany( $related : string [, $foreignKey : string = null ] [, $localKey : string = null ] ) : HasManySyncable
Parameters
$related : string
$foreignKey : string = null
$localKey : string = null
Return values
HasManySyncable

morphMany()

Overrides the default Eloquent morphMany relationship to return a MorphManySyncable.

public morphMany( $related : string , $name : string [, $type : string = null ] [, $id : string = null ] [, $localKey : string = null ] ) : MorphManySyncable
Parameters
$related : string
$name : string
$type : string = null
$id : string = null
$localKey : string = null
Return values
MorphManySyncable

belongsToManyThrough()

Define a many-to-many 'through' relationship.

public belongsToManyThrough( $related : string , $through : string [, $firstJoiningTable : string = null ] [, $firstForeignPivotKey : string = null ] [, $firstRelatedKey : string = null ] [, $secondJoiningTable : string = null ] [, $secondForeignPivotKey : string = null ] [, $secondRelatedKey : string = null ] [, $throughRelation : string = null ] [, $relation : string = null ] ) : BelongsToManyThrough

This is basically hasManyThrough for many-to-many relationships.

Parameters
$related : string
$through : string
$firstJoiningTable : string = null
$firstForeignPivotKey : string = null
$firstRelatedKey : string = null
$secondJoiningTable : string = null
$secondForeignPivotKey : string = null
$secondRelatedKey : string = null
$throughRelation : string = null
$relation : string = null
Return values
BelongsToManyThrough

belongsToManyUnique()

Define a unique many-to-many relationship. Similar to a regular many-to-many relationship, but removes duplicate child objects.

public belongsToManyUnique( $related : string [, $table : string = null ] [, $foreignPivotKey : string = null ] [, $relatedPivotKey : string = null ] [, $parentKey : string = null ] [, $relatedKey : string = null ] [, $relation : string = null ] ) : BelongsToManyUnique

Can also be used to implement ternary relationships.

Parameters
$related : string
$table : string = null
$foreignPivotKey : string = null
$relatedPivotKey : string = null
$parentKey : string = null
$relatedKey : string = null
$relation : string = null
Return values
BelongsToManyUnique

morphToManyUnique()

Define a unique morphs-to-many relationship. Similar to a regular morphs-to-many relationship, but removes duplicate child objects.

public morphToManyUnique( $related : string , $name : string [, $table : string = null ] [, $foreignPivotKey : string = null ] [, $relatedPivotKey : string = null ] [, $parentKey : string = null ] [, $relatedKey : string = null ] [, $inverse : bool = false ] ) : MorphToManyUnique
Parameters
$related : string
$name : string
$table : string = null
$foreignPivotKey : string = null
$relatedPivotKey : string = null
$parentKey : string = null
$relatedKey : string = null
$inverse : bool = false
Return values
MorphToManyUnique

getBelongsToManyCaller()

Get the relationship name of the belongs to many.

protected getBelongsToManyCaller( ) : string
Return values
string

Search results