Browse Source

移除EloquentRepository无效代码

jqh 5 years ago
parent
commit
9d814a56d0
1 changed files with 5 additions and 37 deletions
  1. 5 37
      src/Repositories/EloquentRepository.php

+ 5 - 37
src/Repositories/EloquentRepository.php

@@ -279,7 +279,7 @@ class EloquentRepository extends Repository implements TreeRepository
         }
         }
 
 
         $this->model = $query
         $this->model = $query
-            ->with($this->getRelations($form))
+            ->with($this->getRelations())
             ->findOrFail($form->getKey(), $this->getFormColumns());
             ->findOrFail($form->getKey(), $this->getFormColumns());
 
 
         return $this->model->toArray();
         return $this->model->toArray();
@@ -301,7 +301,7 @@ class EloquentRepository extends Repository implements TreeRepository
         }
         }
 
 
         $this->model = $query
         $this->model = $query
-            ->with($this->getRelations($show))
+            ->with($this->getRelations())
             ->findOrFail($show->getKey(), $this->getDetailColumns());
             ->findOrFail($show->getKey(), $this->getDetailColumns());
 
 
         return $this->model->toArray();
         return $this->model->toArray();
@@ -518,7 +518,7 @@ class EloquentRepository extends Repository implements TreeRepository
         $id = $form->getKey();
         $id = $form->getKey();
 
 
         return $query
         return $query
-            ->with($this->getRelations($form))
+            ->with($this->getRelations())
             ->findOrFail(
             ->findOrFail(
                 collect(explode(',', $id))->filter()->toArray(),
                 collect(explode(',', $id))->filter()->toArray(),
                 $this->getFormColumns()
                 $this->getFormColumns()
@@ -652,41 +652,9 @@ class EloquentRepository extends Repository implements TreeRepository
      *
      *
      * @return array
      * @return array
      */
      */
-    protected function getRelations($builder)
+    protected function getRelations()
     {
     {
-        $relations = $columns = [];
-
-        if ($builder instanceof Form) {
-            /** @var Form\Field $field */
-            foreach ($builder->builder()->fields() as $field) {
-                $columns[] = $field->column();
-            }
-        } elseif ($builder instanceof Show) {
-            /** @var Show\Field $field */
-            foreach ($builder->fields() as $field) {
-                $columns[] = $field->getName();
-            }
-        }
-
-        $model = $this->eloquent();
-
-        foreach (Arr::flatten($columns) as $column) {
-            if (Str::contains($column, '.')) {
-                [$relation] = explode('.', $column);
-
-                if (method_exists($model, $relation) &&
-                    $model->$relation() instanceof Relations\Relation
-                ) {
-                    $relations[] = $relation;
-                }
-            } elseif (method_exists($model, $column) &&
-                ! method_exists(EloquentModel::class, $column)
-            ) {
-                $relations[] = $column;
-            }
-        }
-
-        return array_unique(array_merge($relations, $this->relations));
+        return $this->relations;
     }
     }
 
 
     /**
     /**