PHP code example of bytexr / filament-queueable-bulk-actions

1. Go to this page and download the library: Download bytexr/filament-queueable-bulk-actions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bytexr / filament-queueable-bulk-actions example snippets


use \Bytexr\QueueableBulkActions\QueueableBulkActionsPlugin;
use Filament\View\PanelsRenderHook;
\Bytexr\QueueableBulkActions\Enums\StatusEnum;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            QueueableBulkActionsPlugin::make()
                ->bulkActionModel(YourBulkActionModel::class) // (optional) - Allows you to register your own model which extends \Bytexr\QueueableBulkActions\Models\BulkAction
                ->bulkActionRecordModel(YourBulkActionRecordModel::class) // (optional) - Allows you to register your own model for records which extends \Bytexr\QueueableBulkActions\Models\BulkActionRecord
                ->renderHook(PanelsRenderHook::RESOURCE_PAGES_LIST_RECORDS_TABLE_BEFORE) // (optional) - Allows you to change where notification is rendered, multiple render hooks can be passed as array [Default: PanelsRenderHook::RESOURCE_PAGES_LIST_RECORDS_TABLE_BEFORE]
                ->pollingInterval('5s') // (optional) - Allows you to change or disable polling interval, set to null to disable. [Default: 5s]
                ->queue('redis', 'default')  // (optional) - Allows you to change which connection and queue should be used [Default: env('QUEUE_CONNECTION'), default]
                ->resource(YourBulkActionResource::class) // (optional) - Allows you to change which resource should be used to display historical bulk actions
                ->colors([
                    StatusEnum::QUEUED->value => 'slate',
                    StatusEnum::IN_PROGRESS->value => 'info',
                    StatusEnum::FINISHED->value => 'success',
                    StatusEnum::FAILED->value => 'danger',
                ]), // (optional) - Allows you to change notification and badge colors used for statuses. Uses filament colors defined in panel provider. [Default: as show in method]
        ]);
}



namespace App\Jobs;

use Bytexr\QueueableBulkActions\Filament\Actions\ActionResponse;
use Bytexr\QueueableBulkActions\Jobs\BulkActionJob;

class DeleteUserBulkActionJob extends BulkActionJob
{
    protected function action($record, ?array $data): ActionResponse
    {
        if($record->isAdmin()) {
            return  ActionResponse::make()
                             ->failure()
                             ->message('Admin users cannot be deleted');
        }
    
        return ActionResponse::make()
                             ->success();
    }
}

...
->bulkActions([
    QueueableBulkAction::make('delete_user')
                        ->label('Delete selected')
                        ->job(DeleteUserBulkActionJob::class)
])
bash
php artisan vendor:publish --tag="queueable-bulk-actions-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="queueable-bulk-actions-config"
bash
php artisan vendor:publish --tag="queueable-bulk-actions-views"