소스 검색

Merge pull request #114 from youyingxiang/master

快捷创建增加action和method方法
Jiang Qinghua 5 년 전
부모
커밋
3eae641e09
1개의 변경된 파일32개의 추가작업 그리고 3개의 파일을 삭제
  1. 32 3
      src/Grid/Tools/QuickCreate.php

+ 32 - 3
src/Grid/Tools/QuickCreate.php

@@ -22,7 +22,14 @@ class QuickCreate implements Renderable
      * @var Collection
      */
     protected $fields;
-
+    /**
+     * @var string
+     */
+    protected $action;
+    /**
+     * @var string
+     */
+    protected $method;
     /**
      * QuickCreate constructor.
      *
@@ -32,6 +39,8 @@ class QuickCreate implements Renderable
     {
         $this->parent = $grid;
         $this->fields = Collection::make();
+        $this->action = request()->url();
+        $this->method = "POST";
     }
 
     protected function formatPlaceholder($placeholder)
@@ -260,10 +269,30 @@ class QuickCreate implements Renderable
 
         return "admin::grid.quick-create.{$name}";
     }
+    /**
+     * @param $action
+     * @return $this
+     */
+    public function action($action)
+    {
+        $this->action = admin_url($action);
+        return $this;
+    }
+
+    /**
+     * @param string $method
+     * @return $this
+     */
+    public function method($method = "POST")
+    {
+        $this->method = $method;
+        return $this;
+    }
 
     protected function script()
     {
-        $url = request()->url();
+        $url = $this->action;
+        $method = $this->method;
 
         $uniqueName = $this->parent->getName();
 
@@ -305,7 +334,7 @@ class QuickCreate implements Renderable
     
         $.ajax({
             url: '{$url}',
-            type: 'POST',
+            type: '{$method}',
             data: $(this).serialize(),
             success: function(data) {
                 ctr.attr('submitting', '');