Skip to content

Commit

Permalink
Merge pull request #12292 from binaryfire/configure-broadcasting-per-…
Browse files Browse the repository at this point in the history
…panel

Allow disabling broadcasting per-panel
  • Loading branch information
danharrin committed Apr 11, 2024
2 parents 35787e0 + dd7b1bb commit 05672bf
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/panels/docs/09-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,18 @@ public function panel(Panel $panel): Panel
], isPersistent: true);
}
```

## Disabling broadcasting

By default, Laravel Echo will automatically connect for every panel, if credentials have been set up in the [published `config/filament.php` configuration file](installation#publishing-configuration). To disable this automatic connection in a panel, you can use the `broadcasting(false)` method:

```php
use Filament\Panel;

public function panel(Panel $panel): Panel
{
return $panel
// ...
->broadcasting(false);
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
@filamentScripts(withCore: true)
@if (config('filament.broadcasting.echo'))
@if (filament()->hasBroadcasting() && config('filament.broadcasting.echo'))
<script data-navigate-once>
window.Echo = new window.EchoFactory(@js(config('filament.broadcasting.echo')))
Expand Down
5 changes: 5 additions & 0 deletions packages/panels/src/FilamentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,11 @@ public function hasBreadcrumbs(): bool
return $this->getCurrentPanel()->hasBreadcrumbs();
}

public function hasBroadcasting(): bool
{
return $this->getCurrentPanel()->hasBroadcasting();
}

public function hasCollapsibleNavigationGroups(): bool
{
return $this->getCurrentPanel()->hasCollapsibleNavigationGroups();
Expand Down
1 change: 1 addition & 0 deletions packages/panels/src/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Panel extends Component
use Panel\Concerns\HasBrandLogo;
use Panel\Concerns\HasBrandName;
use Panel\Concerns\HasBreadcrumbs;
use Panel\Concerns\HasBroadcasting;
use Panel\Concerns\HasColors;
use Panel\Concerns\HasComponents;
use Panel\Concerns\HasDarkMode;
Expand Down
22 changes: 22 additions & 0 deletions packages/panels/src/Panel/Concerns/HasBroadcasting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Filament\Panel\Concerns;

use Closure;

trait HasBroadcasting
{
protected bool | Closure $hasBroadcasting = true;

public function broadcasting(bool | Closure $condition = true): static
{
$this->hasBroadcasting = $condition;

return $this;
}

public function hasBroadcasting(): bool
{
return (bool) $this->evaluate($this->hasBroadcasting);
}
}

0 comments on commit 05672bf

Please sign in to comment.