How to Hide/Show Bulk Action based on active Tab?
I have tried as below:
I want visible true when activeTab= "is_archived" for reset of tabs, don't want to display above action to bulk action.
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()
3 Replies
As of now I have managing other way as below instead of visible()
Helper:
May it will help to anyone
For visible we can do like this:
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;
}
);
->visible(!getQueryStringParamValue('activeTab') || getQueryStringParamValue('activeTab') !== "is_archived")
->visible(!getQueryStringParamValue('activeTab') || getQueryStringParamValue('activeTab') !== "is_archived")
->visible(fn ($livewire): bool => $livewire->activeTab === 'is_archived')
->visible(fn ($livewire): bool => $livewire->activeTab === 'is_archived')
Let me try this
Yes, Its working fine. Thanks a lot sir ❤️