HasOne
class HasOne extends HasOneOrMany (View source)
Methods
Create a new has one or many relationship instance.
Set the constraints for an eager load of the relation.
Initialize the relation on a set of models.
Match the eagerly loaded results to their parents.
Get the results of the relationship.
Add the constraints for a relationship count query.
Set or get the morph map for polymorphic relations.
Handle dynamic method calls to the relationship.
Add the constraints for a relationship count query on the same table.
Match the eagerly loaded results to their single parents.
Match the eagerly loaded results to their many parents.
Find a model by its primary key or return new instance of the related model.
Get the first related model record matching the attributes or instantiate it.
Get the first related record matching the attributes or create it.
Create or update a related record matching the attributes, and fill it with values.
Create an array of new instances of the related model.
Get the key for comparing against the parent key in "has" query.
Details
in HasOneOrMany at line line 35
void
__construct(
Builder $query,
Model $parent,
string $foreignKey,
string $localKey)
Create a new has one or many relationship instance.
in HasOneOrMany at line line 48
void
addConstraints()
Set the base constraints on the relation query.
in HasOneOrMany at line line 109
void
addEagerConstraints(
array $models)
Set the constraints for an eager load of the relation.
at line line 26
array
initRelation(
array $models,
string $relation)
Initialize the relation on a set of models.
at line line 43
array
match(
array $models,
Collection $results,
string $relation)
Match the eagerly loaded results to their parents.
in HasOneOrMany at line line 64
Builder
getRelationCountQuery(
Builder $query,
Builder $parent)
Add the constraints for a relationship count query.
static
mixed
noConstraints(
Closure $callback)
Run a callback with constraints disabled on the relation.
in HasOneOrMany at line line 401
string
getQualifiedParentKeyName()
Get the fully qualified parent key name.
static
array
morphMap(
array $map = null,
bool $merge = true)
Set or get the morph map for polymorphic relations.
in HasOneOrMany at line line 80
Builder
getRelationCountQueryForSelfRelation(
Builder $query,
Builder $parent)
Add the constraints for a relationship count query on the same table.
in HasOneOrMany at line line 122
array
matchOne(
array $models,
Collection $results,
string $relation)
Match the eagerly loaded results to their single parents.
in HasOneOrMany at line line 135
array
matchMany(
array $models,
Collection $results,
string $relation)
Match the eagerly loaded results to their many parents.
in HasOneOrMany at line line 212
Model
save(
Model $model)
Attach a model instance to the parent model.
in HasOneOrMany at line line 225
Collection|array
saveMany(
Collection|array $models)
Attach a collection of models to the parent instance.
in HasOneOrMany at line line 241
Collection|Model
findOrNew(
mixed $id,
array $columns = array('*'))
Find a model by its primary key or return new instance of the related model.
in HasOneOrMany at line line 258
Model
firstOrNew(
array $attributes)
Get the first related model record matching the attributes or instantiate it.
in HasOneOrMany at line line 275
Model
firstOrCreate(
array $attributes)
Get the first related record matching the attributes or create it.
in HasOneOrMany at line line 291
Model
updateOrCreate(
array $attributes,
array $values = array())
Create or update a related record matching the attributes, and fill it with values.
in HasOneOrMany at line line 308
Model
create(
array $attributes)
Create a new instance of the related model.
in HasOneOrMany at line line 328
array
createMany(
array $records)
Create an array of new instances of the related model.
in HasOneOrMany at line line 345
int
update(
array $attributes)
Perform an update on all the related models.
in HasOneOrMany at line line 359
string
getHasCompareKey()
Get the key for comparing against the parent key in "has" query.