Skip to content

Commit db463e4

Browse files
committed
Fix docblocks and indenting.
1 parent 404e791 commit db463e4

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

src/ElasticquentTrait.php

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ public function updateIndex()
362362
* Get Search Document
363363
*
364364
* Retrieve an ElasticSearch document
365-
* for this enty.
365+
* for this entity.
366366
*
367367
* @return array
368368
*/
@@ -609,10 +609,10 @@ public static function typeExists()
609609
*/
610610
public function newFromHitBuilder($hit = array())
611611
{
612-
$keyname = $this->getKeyName();
612+
$key_name = $this->getKeyName();
613613

614614
$attributes = $hit['_source'];
615-
$attributes[$keyname] = is_numeric($hit['_id']) ? intval($hit['_id']) : $hit['_id'];
615+
$attributes[$key_name] = is_numeric($hit['_id']) ? intval($hit['_id']) : $hit['_id'];
616616

617617
// Add fields to attributes
618618
if (isset($hit['fields'])) {
@@ -644,7 +644,7 @@ public function newFromHitBuilder($hit = array())
644644
*
645645
* @param \Illuminate\Database\Eloquent\Model $model
646646
* @param array $attributes
647-
* @param \Illuminate\Database\Eloquent\Relation $parentRelation
647+
* @param \Illuminate\Database\Eloquent\Relations\Relation $parentRelation
648648
* @return static
649649
*/
650650
public static function newFromBuilderRecursive(Model $model, array $attributes = [], Relation $parentRelation = null)
@@ -664,9 +664,9 @@ public static function newFromBuilderRecursive(Model $model, array $attributes =
664664
/**
665665
* Create a collection of models from plain arrays recursive.
666666
*
667-
* @param \Illuminate\Database\Eloquent\Model $model
668-
* @param \Illuminate\Database\Eloquent\Relation $parentRelation
669-
* @param array $items
667+
* @param \Illuminate\Database\Eloquent\Model $model
668+
* @param \Illuminate\Database\Eloquent\Relations\Relation $parentRelation
669+
* @param array $items
670670
* @return \Illuminate\Database\Eloquent\Collection
671671
*/
672672
public static function hydrateRecursive(Model $model, array $items, Relation $parentRelation = null)
@@ -683,36 +683,41 @@ public static function hydrateRecursive(Model $model, array $items, Relation $pa
683683
/**
684684
* Get the relations attributes from a model.
685685
*
686-
* @param \Illuminate\Database\Eloquent\Model $model
686+
* @param \Illuminate\Database\Eloquent\Model $model
687687
*/
688688
public static function loadRelationsAttributesRecursive(Model $model)
689-
{
690-
$attributes = $model->getAttributes();
691-
foreach ($attributes as $key => $value) {
692-
if (method_exists($model, $key) ) {
693-
$refl = new ReflectionMethod($model, $key);
694-
if($refl->class != "Illuminate\Database\Eloquent\Model"){
695-
$relation = $model->$key();
696-
if ($relation instanceof Relation) {
697-
// Check if the relation field is single model or collections
698-
if (!static::isMultiLevelArray($value)) {
699-
$value = [$value];
689+
{
690+
$attributes = $model->getAttributes();
691+
692+
foreach ($attributes as $key => $value) {
693+
if (method_exists($model, $key)) {
694+
$reflection_method = new ReflectionMethod($model, $key);
695+
696+
if ($reflection_method->class != "Illuminate\Database\Eloquent\Model") {
697+
$relation = $model->$key();
698+
699+
if ($relation instanceof Relation) {
700+
// Check if the relation field is single model or collections
701+
if (!static::isMultiLevelArray($value)) {
702+
$value = [$value];
703+
}
704+
705+
$models = static::hydrateRecursive($relation->getModel(), $value, $relation);
706+
707+
// Unset attribute before match relation
708+
unset($model[$key]);
709+
$relation->match([$model], $models, $key);
710+
}
711+
}
700712
}
701-
$models = static::hydrateRecursive($relation->getModel(), $value, $relation);
702-
// Unset attribute before match relation
703-
unset($model[$key]);
704-
$relation->match([$model], $models, $key);
705-
}
706713
}
707-
}
708714
}
709-
}
710715

711716
/**
712717
* Get the pivot attribute from a model.
713718
*
714719
* @param \Illuminate\Database\Eloquent\Model $model
715-
* @param \Illuminate\Database\Eloquent\Relation $parentRelation
720+
* @param \Illuminate\Database\Eloquent\Relations\Relation $parentRelation
716721
*/
717722
public static function loadPivotAttribute(Model $model, Relation $parentRelation = null)
718723
{

0 commit comments

Comments
 (0)