HasOneOrMany
Extends
Uses
Properties
$foreignKey string
The foreign key of the parent model.
$localKey string
The local key of the parent model.
Methods
__construct ( Builder $query , Model $parent , $foreignKey , $localKey ) : void
Create a new has one or many relationship instance.
Parameters
make ( array $attributes ) : Model
Create and return an un-saved instance of the related model.
Parameters
- $attributes array
makeMany ( $records ) : Collection
Create and return an un-saved instance of the related models.
Parameters
- $records iterable
addConstraints ( ) : void
Set the base constraints on the relation query.
addEagerConstraints ( array $models ) : void
Set the constraints for an eager load of the relation.
Parameters
- $models array
matchOne ( array $models , Collection $results , $relation ) : array
Match the eagerly loaded results to their single parents.
Parameters
- $models array
- $results Collection
- $relation string
matchMany ( array $models , Collection $results , $relation ) : array
Match the eagerly loaded results to their many parents.
Parameters
- $models array
- $results Collection
- $relation string
matchOneOrMany ( array $models , Collection $results , $relation , $type ) : array
Match the eagerly loaded results to their many parents.
Parameters
- $models array
- $results Collection
- $relation string
- $type string
getRelationValue ( array $dictionary , $key , $type ) : mixed
Get the value of a relationship by one or many type.
Parameters
- $dictionary array
- $key string
- $type string
buildDictionary ( Collection $results ) : array
Build model dictionary keyed by the relation's foreign key.
Parameters
- $results Collection
findOrNew ( $id , $columns ) : Collection |Model
Find a model by its primary key or return a new instance of the related model.
Parameters
- $id mixed
- $columns array
firstOrNew ( array $attributes , array $values ) : Model
Get the first related model record matching the attributes or instantiate it.
Parameters
- $attributes array
- $values array
firstOrCreate ( array $attributes , array $values ) : Model
Get the first related record matching the attributes or create it.
Parameters
- $attributes array
- $values array
updateOrCreate ( array $attributes , array $values ) : Model
Create or update a related record matching the attributes, and fill it with values.
Parameters
- $attributes array
- $values array
save ( Model $model ) : Model |false
Attach a model instance to the parent model.
Parameters
- $model Model
saveMany ( $models ) : iterable
Attach a collection of models to the parent instance.
Parameters
- $models iterable
create ( array $attributes ) : Model
Create a new instance of the related model.
Parameters
- $attributes array
forceCreate ( array $attributes ) : Model
Create a new instance of the related model. Allow mass-assignment.
Parameters
- $attributes array
createMany ( iterable $records ) : Collection
Create a Collection of new instances of the related model.
Parameters
- $records iterable
setForeignAttributesForCreate ( Model $model ) : void
Set the foreign ID for creating a related model.
Parameters
- $model Model
getRelationExistenceQuery ( Builder $query , Builder $parentQuery , $columns ) : Builder
Add the constraints for a relationship query.
Parameters
getRelationExistenceQueryForSelfRelation ( Builder $query , Builder $parentQuery , $columns ) : Builder
Add the constraints for a relationship query on the same table.
Parameters
getExistenceCompareKey ( ) : string
Get the key for comparing against the parent key in "has" query.
getParentKey ( ) : mixed
Get the key value of the parent's local key.
getQualifiedParentKeyName ( ) : string
Get the fully qualified parent key name.
getForeignKeyName ( ) : string
Get the plain foreign key.
getQualifiedForeignKeyName ( ) : string
Get the foreign key for the relationship.
getLocalKeyName ( ) : string
Get the local key for the relationship.