Skip to content

Commit ed39d32

Browse files
committed
feat: Add addScriptIfCan method
1 parent 869b050 commit ed39d32

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Html/Builder.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Contracts\Config\Repository;
66
use Illuminate\Contracts\View\Factory;
77
use Illuminate\Support\Collection;
8+
use Illuminate\Support\Facades\Gate;
89
use Illuminate\Support\HtmlString;
910
use Illuminate\Support\Traits\Macroable;
1011
use Yajra\DataTables\Utilities\Helper;
@@ -263,4 +264,13 @@ public function addScript(string $view): static
263264

264265
return $this;
265266
}
267+
268+
public function addScriptIfCan(string $permission, string $view): static
269+
{
270+
if (Gate::allows($permission)) {
271+
$this->addScript($view);
272+
}
273+
274+
return $this;
275+
}
266276
}

0 commit comments

Comments
 (0)