F
Filament10mo ago
Sandeep

How to Hide/Show Bulk Action based on active Tab?

I have tried as below:
Tables\Actions\BulkAction::make('bulk_revert_archive')
->label('Remove From Archived')
->visible(isset(request()->query()['activeTab']) && request()->query()['activeTab'] === "is_archived")
->requiresConfirmation()
Tables\Actions\BulkAction::make('bulk_revert_archive')
->label('Remove From Archived')
->visible(isset(request()->query()['activeTab']) && request()->query()['activeTab'] === "is_archived")
->requiresConfirmation()
I want visible true when activeTab= "is_archived" for reset of tabs, don't want to display above action to bulk action.
No description
3 Replies
Sandeep
SandeepOP10mo ago
As of now I have managing other way as below instead of visible() Helper:
if (!function_exists('getQueryStringParamValue')) {
function getQueryStringParamValue($param = null)
{
if (!$param)
return null;

// Get the referer from the server array
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';

// Parse the URL to get the query string
$queryString = parse_url($referer, PHP_URL_QUERY);

// Initialize an array to store parameters
$paramsArray = [];

// Parse the query string to get individual parameters
parse_str($queryString, $paramsArray);

// Get the value of the parameter
return isset($paramsArray[$param]) ? $paramsArray[$param] : null;

}
}
if (!function_exists('getQueryStringParamValue')) {
function getQueryStringParamValue($param = null)
{
if (!$param)
return null;

// Get the referer from the server array
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';

// Parse the URL to get the query string
$queryString = parse_url($referer, PHP_URL_QUERY);

// Initialize an array to store parameters
$paramsArray = [];

// Parse the query string to get individual parameters
parse_str($queryString, $paramsArray);

// Get the value of the parameter
return isset($paramsArray[$param]) ? $paramsArray[$param] : null;

}
}
In Action of Bulk Action:
->action(function (Collection $records, \Mavinoo\Batch\Batch $batch): void {

if (getQueryStringParamValue('activeTab') && getQueryStringParamValue('activeTab') === "is_archived") {
Notification::make('check_archived')
->title('Selected records are already archived.')
->warning()
->send();
return;
}
);
In Action of Bulk Action:
->action(function (Collection $records, \Mavinoo\Batch\Batch $batch): void {

if (getQueryStringParamValue('activeTab') && getQueryStringParamValue('activeTab') === "is_archived") {
Notification::make('check_archived')
->title('Selected records are already archived.')
->warning()
->send();
return;
}
);
May it will help to anyone For visible we can do like this:
->visible(!getQueryStringParamValue('activeTab') || getQueryStringParamValue('activeTab') !== "is_archived")
->visible(!getQueryStringParamValue('activeTab') || getQueryStringParamValue('activeTab') !== "is_archived")
LeandroFerreira
LeandroFerreira10mo ago
->visible(fn ($livewire): bool => $livewire->activeTab === 'is_archived')
->visible(fn ($livewire): bool => $livewire->activeTab === 'is_archived')
Sandeep
SandeepOP10mo ago
Let me try this Yes, Its working fine. Thanks a lot sir ❤️
Want results from more Discord servers?
Add your server