Skip to main content

Overview

Panels are the central configuration object in WireChat. They act as a container for all chat-related settings, behaviors, and customizations. Think of a Panel as the “control center” for your chat application.

What is a Panel?

A Panel is the main entry point for configuring WireChat. It uses a fluent interface pattern that allows you to chain configuration methods together. Each Panel can be customized with colors, layouts, authentication, broadcasting, middleware, and more.
use Wirechat\Wirechat\Panel;

$panel = Panel::make()
    ->default()
    ->register();

Panel Architecture

The Panel class is built using multiple trait-based concerns, making it highly modular and extensible:
class Panel
{
    use EvaluatesClosures;
    use HasActions;
    use HasAttachments;
    use HasAuth;
    use HasBroadcasting;
    use HasChatActions;
    use HasChatMiddleware;
    use HasChatsSearch;
    use HasColors;
    use HasDeleteMessageActions;
    use HasEmojiPicker;
    use HasFavicon;
    use HasGroupActions;
    use HasGroups;
    use HasHeading;
    use HasHeart;
    use HasId;
    use HasLayout;
    use HasMiddleware;
    use HasRoutes;
    use HasSearchableAttributes;
    use HasUsersSearch;
    use HasWebPushNotifications;
}

Creating a Panel

Panels are created using the static make() method, which leverages Laravel’s service container:
use Wirechat\Wirechat\Panel;

// Create a new panel instance
$panel = Panel::make();
The make() method uses app(static::class) internally, allowing for dependency injection and singleton behavior.

Default Panel

You can mark a panel as the default panel for your application:
$panel = Panel::make()
    ->default();

// Check if a panel is default
if ($panel->isDefault()) {
    // This is the default panel
}
The default() method accepts a boolean or Closure:
// Conditional default
$panel->default(fn () => auth()->user()->isAdmin());

Panel Configuration Traits

Each trait provides specific configuration capabilities:
Configure authentication and user management for your chat.
Set up real-time broadcasting for live chat updates.
Customize the color scheme of your chat interface.
Configure the visual layout and structure of the chat UI.
Enable and configure group chat functionality.
Configure file upload and attachment handling.
Add middleware to protect chat routes and actions.
Enable push notifications for chat messages.

Registration

After configuring your panel, register it to apply all settings:
$panel = Panel::make()
    ->default()
    ->register();
The register() method is called to finalize the panel configuration and make it active in your application.

Closure Evaluation

Panels support closure-based configuration through the EvaluatesClosures trait. This allows you to defer configuration logic until runtime:
$panel->default(fn () => \Illuminate\Support\Facades\Auth::check());
The evaluate() method is used internally to resolve closures:
public function isDefault(): bool
{
    return $this->evaluate($this->isDefault);
}

Best Practices

  • Create one default panel for your application
  • Use closures for dynamic configuration based on user context
  • Register your panel in a service provider for consistency
  • Chain configuration methods for clean, readable setup code

Next Steps

Conversations

Learn about conversation types and management

Messages

Understand message handling and types