From 9688e01699776dda0d8aa75143d1fc21cab38f76 Mon Sep 17 00:00:00 2001 From: Harvey Christian Pacleb Date: Wed, 1 Oct 2025 01:36:43 +0800 Subject: [PATCH 1/2] feat: Add addScriptIfCannot 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..12310b3 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 addScriptIfCannot(string $permission, string $view): static + { + if (! (Gate::allows($permission))) { + $this->addScript($view); + } + + return $this; + } } From 3b01294d5c8c138f9490b2467fe95e87f0226c24 Mon Sep 17 00:00:00 2001 From: Harvey Christian Pacleb Date: Wed, 1 Oct 2025 09:05:27 +0800 Subject: [PATCH 2/2] fix: Follow laravel convention for variable name Co-authored-by: Arjay Angeles --- 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 12310b3..4bf7562 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 addScriptIfCannot(string $permission, string $view): static + public function addScriptIfCannot(string $ability, string $view): static { - if (! (Gate::allows($permission))) { + if (! (Gate::allows($ability))) { $this->addScript($view); }