Skip to content

Commit 252eada

Browse files
authored
Merge pull request #249 from hpacleb/feat-add-script-if-cannot-method
feat: Add addScriptIfCannot method
2 parents f9f0951 + 48788ea commit 252eada

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;
@@ -264,6 +265,15 @@ public function addScript(string $view): static
264265
return $this;
265266
}
266267

268+
public function addScriptIfCannot(string $ability, string $view): static
269+
{
270+
if (! (Gate::allows($ability))) {
271+
$this->addScript($view);
272+
}
273+
274+
return $this;
275+
}
276+
267277
public function getTemplate(): string
268278
{
269279
return $this->template;

0 commit comments

Comments
 (0)