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 ) : Illuminate\...\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 , Illuminate\...\Collection $results , $relation ) : array
Match the eagerly loaded results to their single parents.
Parameters
- $models array
- $results Illuminate\...\Collection
- $relation string
matchMany ( array $models , Illuminate\...\Collection $results , $relation ) : array
Match the eagerly loaded results to their many parents.
Parameters
- $models array
- $results Illuminate\...\Collection
- $relation string
matchOneOrMany ( array $models , Illuminate\...\Collection $results , $relation , $type ) : array
Match the eagerly loaded results to their many parents.
Parameters
- $models array
- $results Illuminate\...\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 ( Illuminate\...\Collection $results ) : array
Build model dictionary keyed by the relation's foreign key.
Parameters
- $results Illuminate\...\Collection
findOrNew ( $id , $columns ) : Illuminate\...\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 record matching the attributes. If the record is not found, create it.
Parameters
- $attributes array
- $values array
createOrFirst ( array $attributes , array $values ) : Model
Attempt to create the record. If a unique constraint violation occurs, attempt to find the matching record.
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
saveQuietly ( Model $model ) : Model |false
Attach a model instance without raising any events to the parent model.
Parameters
- $model Model
saveMany ( $models ) : iterable
Attach a collection of models to the parent instance.
Parameters
- $models iterable
saveManyQuietly ( $models ) : iterable
Attach a collection of models to the parent instance without raising any events to the parent model.
Parameters
- $models iterable
create ( array $attributes ) : Model
Create a new instance of the related model.
Parameters
- $attributes array
createQuietly ( array $attributes ) : Model
Create a new instance of the related model without raising any events to the parent model.
Parameters
- $attributes array
forceCreate ( array $attributes ) : Model
Create a new instance of the related model. Allow mass-assignment.
Parameters
- $attributes array
forceCreateQuietly ( array $attributes ) : Model
Create a new instance of the related model with mass assignment without raising model events.
Parameters
- $attributes array
createMany ( iterable $records ) : Illuminate\...\Collection
Create a Collection of new instances of the related model.
Parameters
- $records iterable
createManyQuietly ( iterable $records ) : Illuminate\...\Collection
Create a Collection of new instances of the related model without raising any events to the parent 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.