fsamapoor
fsamapoor
FFilament
Created by fsamapoor on 10/25/2023 in #❓┊help
Is it possible to call a table action from a TextColumn cell?
I have a table in my resource with a few table actions. Is there any way to call one of the actions when the users clicks on a Tables\Columns\TextColumn cell? I have a table action named "show-message-text-modal" and I can select the table action using this closure, I just don't know how to trigger it or call it.
Tables\Columns\TextColumn::make('text')
->placeholder('No text.')
->action(function (Message $record, Table $table) {
$table->getAction('show-message-text-modal');
// I have access to the action
}),
Tables\Columns\TextColumn::make('text')
->placeholder('No text.')
->action(function (Message $record, Table $table) {
$table->getAction('show-message-text-modal');
// I have access to the action
}),
3 replies
FFilament
Created by fsamapoor on 9/27/2023 in #❓┊help
How to access to the selected option in the SelectFilter?
I have provided options to a SelectFilter and everything works as expected. I have a special case where I need to modify the query if one specific option gets selected. How could I access to the selected option? Is it possible to modify the query based on the selected options?
SelectFilter::make('receiver')
->options(self::messageReceiver())
->searchable()
->attribute('chat_id')
SelectFilter::make('receiver')
->options(self::messageReceiver())
->searchable()
->attribute('chat_id')
I thought about chaining when method to the filter, but I just don't know how can I have access to the selected option so that I can replace the true part with the condition.
->when(true, function (BaseFilter $filter) {
return $filter->modifyQueryUsing(function (Builder $query) {
return $query->whereColumn('chat_id', 'sender_id');
});
})
->when(true, function (BaseFilter $filter) {
return $filter->modifyQueryUsing(function (Builder $query) {
return $query->whereColumn('chat_id', 'sender_id');
});
})
5 replies
FFilament
Created by fsamapoor on 9/20/2023 in #❓┊help
How to test Counting relationships
I'm counting the number of related records in a text column based on the documentation and everything works fine.
Tables\Columns\TextColumn::make('messages_count')
->counts('messages'),
Tables\Columns\TextColumn::make('messages_count')
->counts('messages'),
How can I test the relationship count with Pest? I tried to test it by chaining assertTableColumnStateSet method to the table component, but no luck so far. Please tell me if I should provide any further details. The error: Failed asserting that a table column with name [messages_count] has value of [1] for record [1] on the [App\Filament\Resources\TelegramUserResource\Pages\ListTelegramUsers] component. The test:
it('can show the messages count in the table.', function () {
$message = Message::factory()
->has(TelegramUser::factory(), 'telegram_user')
->create();

$telegram_user = $message->telegram_user;

livewire(TelegramUserResource\Pages\ListTelegramUsers::class)
->assertTableColumnStateSet(
name: 'messages_count',
value: 1,
record: $telegram_user,
);
});
it('can show the messages count in the table.', function () {
$message = Message::factory()
->has(TelegramUser::factory(), 'telegram_user')
->create();

$telegram_user = $message->telegram_user;

livewire(TelegramUserResource\Pages\ListTelegramUsers::class)
->assertTableColumnStateSet(
name: 'messages_count',
value: 1,
record: $telegram_user,
);
});
6 replies