jqh 5 anni fa
parent
commit
a16a795d44

+ 2 - 2
src/Actions/Response.php

@@ -145,7 +145,7 @@ class Response
      *
      * @return $this
      */
-    protected function data(array $value)
+    public function data(array $value)
     {
         $this->data = array_merge($this->data, $value);
 
@@ -169,7 +169,7 @@ class Response
     /**
      * @param \Throwable $exception
      *
-     * @return mixed
+     * @return $this
      */
     public static function withException(\Throwable $exception)
     {

+ 9 - 8
src/Auth/Permission.php

@@ -6,15 +6,16 @@ use Dcat\Admin\Admin;
 use Dcat\Admin\Layout\Content;
 use Dcat\Admin\Middleware\Pjax;
 use Dcat\Admin\Models\Role;
+use Illuminate\Contracts\Support\Arrayable;
 
 class Permission
 {
     /**
      * Check permission.
      *
-     * @param $permission
+     * @param string|array|Arrayable $permission
      *
-     * @return true
+     * @return true|void
      */
     public static function check($permission)
     {
@@ -22,12 +23,12 @@ class Permission
             return true;
         }
 
-        if (is_array($permission)) {
+        if (is_array($permission) || $permission instanceof Arrayable) {
             collect($permission)->each(function ($permission) {
                 static::check($permission);
             });
 
-            return;
+            return true;
         }
 
         if (Admin::user()->cannot($permission)) {
@@ -38,9 +39,9 @@ class Permission
     /**
      * Roles allowed to access.
      *
-     * @param $roles
+     * @param string|array|Arrayable $roles
      *
-     * @return true
+     * @return true|void
      */
     public static function allow($roles)
     {
@@ -66,9 +67,9 @@ class Permission
     /**
      * Roles denied to access.
      *
-     * @param $roles
+     * @param string|array|Arrayable $roles
      *
-     * @return true
+     * @return true|void
      */
     public static function deny($roles)
     {

+ 14 - 4
src/Controllers/AdminController.php

@@ -37,6 +37,16 @@ class AdminController extends Controller
         return $this->title;
     }
 
+    /**
+     * Get description for following 4 action pages.
+     *
+     * @return array
+     */
+    protected function description()
+    {
+        return $this->description;
+    }
+
     /**
      * Index interface.
      *
@@ -52,7 +62,7 @@ class AdminController extends Controller
 
         return $content
             ->title($this->title())
-            ->description($this->description['index'] ?? trans('admin.list'))
+            ->description($this->description()['index'] ?? trans('admin.list'))
             ->body($this->grid());
     }
 
@@ -68,7 +78,7 @@ class AdminController extends Controller
     {
         return $content
             ->title($this->title())
-            ->description($this->description['show'] ?? trans('admin.show'))
+            ->description($this->description()['show'] ?? trans('admin.show'))
             ->body($this->detail($id));
     }
 
@@ -84,7 +94,7 @@ class AdminController extends Controller
     {
         return $content
             ->title($this->title())
-            ->description($this->description['edit'] ?? trans('admin.edit'))
+            ->description($this->description()['edit'] ?? trans('admin.edit'))
             ->body($this->form()->edit($id));
     }
 
@@ -99,7 +109,7 @@ class AdminController extends Controller
     {
         return $content
             ->title($this->title())
-            ->description($this->description['create'] ?? trans('admin.create'))
+            ->description($this->description()['create'] ?? trans('admin.create'))
             ->body($this->form());
     }
 

+ 10 - 0
src/Form/Footer.php

@@ -48,6 +48,8 @@ class Footer implements Renderable
     /**
      * Disable reset button.
      *
+     * @param bool $disable
+     *
      * @return $this
      */
     public function disableReset(bool $disable = true)
@@ -64,6 +66,8 @@ class Footer implements Renderable
     /**
      * Disable submit button.
      *
+     * @param bool $disable
+     *
      * @return $this
      */
     public function disableSubmit(bool $disable = true)
@@ -80,6 +84,8 @@ class Footer implements Renderable
     /**
      * Disable View Checkbox.
      *
+     * @param bool $disable
+     *
      * @return $this
      */
     public function disableViewCheck(bool $disable = true)
@@ -96,6 +102,8 @@ class Footer implements Renderable
     /**
      * Disable Editing Checkbox.
      *
+     * @param bool $disable
+     *
      * @return $this
      */
     public function disableEditingCheck(bool $disable = true)
@@ -112,6 +120,8 @@ class Footer implements Renderable
     /**
      * Disable Creating Checkbox.
      *
+     * @param bool $disable
+     *
      * @return $this
      */
     public function disableCreatingCheck(bool $disable = true)

+ 4 - 8
src/Layout/Column.php

@@ -3,7 +3,7 @@
 namespace Dcat\Admin\Layout;
 
 use Dcat\Admin\Grid;
-use Illuminate\Contracts\Support\Renderable;
+use Dcat\Admin\Support\Helper;
 
 class Column implements Buildable
 {
@@ -81,11 +81,7 @@ class Column implements Buildable
 
         $row->build();
 
-        $contents = ob_get_contents();
-
-        ob_end_clean();
-
-        return $this->append($contents);
+        return $this->append(ob_get_clean());
     }
 
     /**
@@ -96,10 +92,10 @@ class Column implements Buildable
         $this->startColumn();
 
         foreach ($this->contents as $content) {
-            if ($content instanceof Renderable || $content instanceof Grid) {
+            if ($content instanceof Grid) {
                 echo $content->render();
             } else {
-                echo (string) $content;
+                echo Helper::render($content);
             }
         }
 

+ 1 - 5
src/Layout/Row.php

@@ -87,10 +87,6 @@ class Row implements Buildable, Renderable
 
         $this->build();
 
-        $contents = ob_get_contents();
-
-        ob_end_clean();
-
-        return $contents;
+        return ob_get_clean();
     }
 }

+ 6 - 2
src/Models/HasPermissions.php

@@ -2,6 +2,8 @@
 
 namespace Dcat\Admin\Models;
 
+use Dcat\Admin\Support\Helper;
+use Illuminate\Contracts\Support\Arrayable;
 use Illuminate\Support\Collection;
 
 trait HasPermissions
@@ -82,6 +84,7 @@ trait HasPermissions
      */
     public function isRole(string $role) : bool
     {
+        /* @var Collection $roles */
         $roles = $this->roles;
 
         return $roles->pluck('slug')->contains($role) ?:
@@ -91,15 +94,16 @@ trait HasPermissions
     /**
      * Check if user in $roles.
      *
-     * @param array $roles
+     * @param string|array|Arrayable $roles
      *
      * @return mixed
      */
     public function inRoles($roles = []) : bool
     {
+        /* @var Collection $all */
         $all = $this->roles;
 
-        $roles = (array) $roles;
+        $roles = Helper::array($roles);
 
         return $all->pluck('slug')->intersect($roles)->isNotEmpty() ?:
             $all->pluck('id')->intersect($roles)->isNotEmpty();