PHP code example of encoredigitalgroup / laravel-operations

1. Go to this page and download the library: Download encoredigitalgroup/laravel-operations 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/ */

    

encoredigitalgroup / laravel-operations example snippets


// config/one-time-operation.php

return [
    'directory' => 'operations',
    'table' => 'operations',
];


// operations/XXXX_XX_XX_XXXXXX_awesome_operation.php

use EncoreDigitalGroup\LaravelOperations\LaravelOperation;

return new class extends LaravelOperation
{
    /**
     * Determine if the operation is being processed asynchronously.
     */
    protected bool $async = true;

    /**
     * The queue that the job will be dispatched to.
     */
    protected string $queue = 'default';

    /**
     * A tag name, that this operation can be filtered by.
     */
    protected ?string $tag = null;

    /**
     * Process the operation.
     */
    public function process(): void
    {
        //
    }
};


// operations/XXXX_XX_XX_XXXXXX_awesome_operation.php

public function process(): void
{
    User::where('active', 1)->update(['status' => 'awesome']) // make active users awesome
}


// operations/XXXX_XX_XX_XXXXXX_awesome_operation.php

    protected ?string $tag = "awesome";
};
shell
php artisan migrate
shell
php artisan operations:make <operation_name>                // create new operation file
php artisan operations:make <operation_name> -e|--essential // create file without any attributes
shell
...
 - php artisan migrate
 - php artisan operations:process
...
shell
php artisan vendor:publish --provider="EncoreDigitalGroup\LaravelOperations\Providers\LaravelOperationsServiceProvider"
shell
php artisan operations:make AwesomeOperation
shell
php artisan operations:process
shell
php artisan operations:process --async  // force dispatch()
php artisan operations:process --sync   // force dispatchSync()
shell
php artisan operations:process --queue=redis  // force redis queue
shell
php artisan operations:process --isolated
text
 - php artisan operations:process --tag=before-migrations
 - php artisan migrate
 - php artisan operations:process
shell
php artisan operations:process XXXX_XX_XX_XXXXXX_awesome_operation
shell
php artisan operations:process --test