From ed39d32950419305cbea02e44375f211ede7c8d0 Mon Sep 17 00:00:00 2001 From: Harvey Christian Pacleb Date: Wed, 1 Oct 2025 01:33:36 +0800 Subject: [PATCH 1/2] feat: Add addScriptIfCan method --- src/Html/Builder.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Html/Builder.php b/src/Html/Builder.php index 9172874..f6fff56 100644 --- a/src/Html/Builder.php +++ b/src/Html/Builder.php @@ -5,6 +5,7 @@ use Illuminate\Contracts\Config\Repository; use Illuminate\Contracts\View\Factory; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Gate; use Illuminate\Support\HtmlString; use Illuminate\Support\Traits\Macroable; use Yajra\DataTables\Utilities\Helper; @@ -263,4 +264,13 @@ public function addScript(string $view): static return $this; } + + public function addScriptIfCan(string $permission, string $view): static + { + if (Gate::allows($permission)) { + $this->addScript($view); + } + + return $this; + } } From f0e9eb67b3e75fd42ccf21867ce159b1bc967904 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 1 Oct 2025 14:03:07 +0800 Subject: [PATCH 2/2] chore: use $ability variable --- src/Html/Builder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Html/Builder.php b/src/Html/Builder.php index e9a2869..3e3af09 100644 --- a/src/Html/Builder.php +++ b/src/Html/Builder.php @@ -265,9 +265,9 @@ public function addScript(string $view): static return $this; } - public function addScriptIfCan(string $permission, string $view): static + public function addScriptIfCan(string $ability, string $view): static { - if (Gate::allows($permission)) { + if (Gate::allows($ability)) { $this->addScript($view); }