Skip to content

Several shops in one panel

By default the desk shows every conversation of the app. When one panel serves several shops (a tenant each, or an agency’s clients), tell it which conversations belong to the one in front of you. The closure narrows a query of the Laravel AI SDK’s conversations (agent_conversations), and you know which conversation is whose, for example from a table you fill when a chat starts:

use Aparte\FilamentDesk\Desk;
use Filament\Facades\Filament;
use Illuminate\Database\Eloquent\Builder;
Desk::scope(fn (Builder $query) => $query->whereIn(
'agent_conversations.id',
ShopConversation::where('shop_id', Filament::getTenant()->id)->select('conversation_id'),
));

The list, its tabs, the counts in the menu, the statistics and the tab’s title all go through it, and a conversation outside it does not open (404). The desk’s pages are not scoped to a Filament tenant themselves (a conversation belongs to no tenant): the scope is what decides.

Pair it with Desk::team(), which gets the conversation’s id, so that a conversation of one shop notifies that shop’s team and can only be given to it (null when the question is about the desk as a whole):

Desk::team(fn (?string $id) => $id
? ShopConversation::firstWhere('conversation_id', $id)?->shop->team ?? []
: User::query()->where('is_support', true)->get());

Two things stay the whole panel’s: the settings (office hours, notices, who answers first), which then open only to the settings_gate you give, and the saved replies, which every shop’s team reads.