jqh 5 years ago
parent
commit
9395574890
2 changed files with 16 additions and 25 deletions
  1. 5 21
      src/Repositories/EloquentRepository.php
  2. 11 4
      src/Repositories/Repository.php

+ 5 - 21
src/Repositories/EloquentRepository.php

@@ -91,7 +91,7 @@ abstract class EloquentRepository extends Repository
     {
         $eloquent = $this->eloquent();
 
-        $model->getQueries()->merge($this->attributes)->unique()->each(function ($query) use (&$eloquent) {
+        $model->getQueries()->unique()->each(function ($query) use (&$eloquent) {
             if ($query['method'] == 'paginate') {
                 $query['arguments'][1] = $this->getGridColumns();
             } elseif ($query['method'] == 'get') {
@@ -114,12 +114,6 @@ abstract class EloquentRepository extends Repository
     {
         $eloquent = $this->eloquent();
 
-        if ($this->attributes) {
-            collect($this->attributes)->unique()->each(function ($query) use (&$eloquent) {
-                $eloquent = call_user_func_array([$eloquent, $query['method']], $query['arguments'] ?? []);
-            });
-        }
-
         if ($this->isSoftDeletes) {
             $eloquent = $eloquent->withTrashed();
         }
@@ -141,12 +135,6 @@ abstract class EloquentRepository extends Repository
     {
         $eloquent = $this->eloquent();
 
-        if ($this->attributes) {
-            collect($this->attributes)->unique()->each(function ($query) use (&$eloquent) {
-                $eloquent = call_user_func_array([$eloquent, $query['method']], $query['arguments'] ?? []);
-            });
-        }
-
         if ($this->isSoftDeletes) {
             $eloquent = $eloquent->withTrashed();
         }
@@ -316,18 +304,14 @@ abstract class EloquentRepository extends Repository
      */
     public function getDataWhenDeleting(Form $form): array
     {
-        $builder = $this->eloquent()->newQuery();
-
-        if ($this->attributes) {
-            collect($this->attributes)->unique()->each(function ($query) use (&$eloquent) {
-                $eloquent = call_user_func_array([$eloquent, $query['method']], $query['arguments'] ?? []);
-            });
-        }
+        $model = $this->eloquent();
 
         if ($this->isSoftDeletes) {
-            $builder = $builder->withTrashed();
+            $model = $model->withTrashed();
         }
 
+        $builder = $model->newQuery();
+
         $id = $form->getKey();
 
         return $builder

+ 11 - 4
src/Repositories/Repository.php

@@ -245,12 +245,19 @@ abstract class Repository implements \Dcat\Admin\Contracts\Repository
      */
     public function __call($method, $arguments)
     {
-        $this->attributes[] = [
-            'method'    => $method,
-            'arguments' => $arguments,
-        ];
+        $this->attributes[$method] = $arguments;
 
         return $this;
     }
 
+    public function __get($name)
+    {
+        return $this->attributes[$name] ?? null;
+    }
+
+    public function __set($name, $value)
+    {
+        $this->attributes[$name] = $value;
+    }
+
 }