jqh 5 years ago
parent
commit
bec3199572

+ 1 - 2
src/Controllers/RenderableController.php

@@ -16,12 +16,11 @@ class RenderableController
     public function handle(Request $request)
     {
         $class = $request->get('renderable');
-        $key = $request->get('key');
 
         $class = str_replace('_', '\\', $class);
 
         if (class_exists($class)) {
-            return $this->render(new $class($key));
+            return $this->render(new $class($request->all()));
         }
 
         return $class;

+ 1 - 1
src/Grid/Displayers/Modal.php

@@ -48,7 +48,7 @@ JS;
 
     protected function setUpRemoteRenderable(string $modalId, RemoteRenderable $renderable)
     {
-        $renderable->setKey($this->getKey());
+        $renderable->with('key', $this->getKey());
 
         $this->addRenderableModalScript($modalId, $renderable->getUrl());
 

+ 25 - 12
src/Support/RemoteRenderable.php

@@ -11,35 +11,38 @@ abstract class RemoteRenderable implements Renderable
 
     protected static $css = [];
 
-    protected $key;
+    protected $variables = [];
 
     public function __construct($key = null)
     {
-        $this->setKey($key);
+        $this->with($key);
     }
 
-    public function setKey($key)
+    public function with($key, $value = null)
     {
-        $this->key = $key;
+        if (is_array($key)) {
+            $this->variables = array_merge($this->variables, $key);
+        } elseif ($key !== null) {
+            $this->variables[$key] = $value;
+        }
 
         return $this;
     }
 
-    public function getKey()
-    {
-        return $this->key;
-    }
-
     public function getUrl()
     {
-        $data = [
-            'key'        => $this->key,
+        $data = array_merge($this->variables(), [
             'renderable' => str_replace('\\', '_', static::class),
-        ];
+        ]);
 
         return route(admin_api_route('render'), $data);
     }
 
+    public function variables()
+    {
+        return $this->variables;
+    }
+
     public static function collectAssets()
     {
         Admin::js(static::$js);
@@ -50,4 +53,14 @@ abstract class RemoteRenderable implements Renderable
     {
         return new static(...$params);
     }
+
+    public function __set($name, $value)
+    {
+        $this->with($name, $value);
+    }
+
+    public function __get($name)
+    {
+        return $this->variables[$name] ?? null;
+    }
 }