class Illuminate / Database / Eloquent / Relations / HasOneOrMany
You're browsing the documentation for an upcoming version of Laravel. The documentation and features of this release are subject to change.
abstract

HasOneOrMany

Extends

Uses

Properties

protected

$foreignKey string

The foreign key of the parent model.

Default: null
protected

$localKey string

The local key of the parent model.

Default: null

Methods

public

__construct ( Builder $query , Model $parent , $foreignKey , $localKey ) : void

Create a new has one or many relationship instance.

Parameters

public

make ( array $attributes ) : Model

Create and return an un-saved instance of the related model.

Parameters

  • $attributes array
public

makeMany ( $records ) : Illuminate\...\Collection

Create and return an un-saved instance of the related models.

Parameters

  • $records iterable
public

addConstraints ( ) : void

Set the base constraints on the relation query.

public

addEagerConstraints ( array $models ) : void

Set the constraints for an eager load of the relation.

Parameters

  • $models array
public

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
public

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
protected

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
protected

getRelationValue ( array $dictionary , $key , $type ) : mixed

Get the value of a relationship by one or many type.

Parameters

  • $dictionary array
  • $key string
  • $type string
protected

buildDictionary ( Illuminate\...\Collection $results ) : array

Build model dictionary keyed by the relation's foreign key.

Parameters

  • $results Illuminate\...\Collection
public

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
public

firstOrNew ( array $attributes , array $values ) : Model

Get the first related model record matching the attributes or instantiate it.

Parameters

  • $attributes array
  • $values array
public

firstOrCreate ( array $attributes , array $values ) : Model

Get the first related record matching the attributes or create it.

Parameters

  • $attributes array
  • $values array
public

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
public

save ( Model $model ) : Model |false

Attach a model instance to the parent model.

Parameters

public

saveQuietly ( Model $model ) : Model |false

Attach a model instance without raising any events to the parent model.

Parameters

public

saveMany ( $models ) : iterable

Attach a collection of models to the parent instance.

Parameters

  • $models iterable
public

saveManyQuietly ( $models ) : iterable

Attach a collection of models to the parent instance without raising any events to the parent model.

Parameters

  • $models iterable
public

create ( array $attributes ) : Model

Create a new instance of the related model.

Parameters

  • $attributes array
public

createQuietly ( array $attributes ) : Model

Create a new instance of the related model without raising any events to the parent model.

Parameters

  • $attributes array
public

forceCreate ( array $attributes ) : Model

Create a new instance of the related model. Allow mass-assignment.

Parameters

  • $attributes array
public

forceCreateQuietly ( array $attributes ) : Model

Create a new instance of the related model with mass assignment without raising model events.

Parameters

  • $attributes array
public

createMany ( iterable $records ) : Illuminate\...\Collection

Create a Collection of new instances of the related model.

Parameters

  • $records iterable
public

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
protected

setForeignAttributesForCreate ( Model $model ) : void

Set the foreign ID for creating a related model.

Parameters

public

getRelationExistenceQuery ( Builder $query , Builder $parentQuery , $columns ) : Builder

Add the constraints for a relationship query.

Parameters

public

getRelationExistenceQueryForSelfRelation ( Builder $query , Builder $parentQuery , $columns ) : Builder

Add the constraints for a relationship query on the same table.

Parameters

public

getExistenceCompareKey ( ) : string

Get the key for comparing against the parent key in "has" query.

public

getParentKey ( ) : mixed

Get the key value of the parent's local key.

public

getQualifiedParentKeyName ( ) : string

Get the fully qualified parent key name.

public

getForeignKeyName ( ) : string

Get the plain foreign key.

public

getQualifiedForeignKeyName ( ) : string

Get the foreign key for the relationship.

public

getLocalKeyName ( ) : string

Get the local key for the relationship.