logo

Operation

You can generate an operation by following command.

bash
php artisan better:operation NotifySubscribersOperation Blog

INFO

Generated operation will be at app/Modules/BlogModule/Operations/NotifySubscribersOperation.php

Arguments

  • operation : name of the generated operation file
  • module : name of the module where the operation file will be generated

Options

  • --force : the command will fail if there is existing file with the given path and name, this option will delete the existing file and replace with new generated file
  • See more at

Calling Jobs From Operation

WARNING

Operation must extend the Better Laravel operation Laranex\BetterLaravel\Cores\Operation to work with the run or runInQueue method.

Calling jobs from a feature or an operation is straightforward using run method.

php
use App\Domains\Blog\Jobs\NotifyViaEmailJob;
use App\Domains\Blog\Jobs\NotifyViaPushNotificationJob;
use Laranex\BetterLaravel\Cores\Operation;

class NotifySubscribersOperation extends Operation
{
    private array $payload;

    public function __construct(array $payload)
    {
        $this->payload = $payload;
    }

    public function handle(): void
    {
        $this->run(new NotifyViaEmailJob($this->payload));
        
        $this->run(new NotifyViaPushNotificationJob($this->payload));
    }
}

Calling Queue Jobs From Operation

Calling queue jobs from a feature or an operation is straightforward using runInQueue method.

php
use App\Domains\Blog\Jobs\NotifyViaEmailJob;
use App\Domains\Blog\Jobs\NotifyViaPushNotificationJob;
use Laranex\BetterLaravel\Cores\Operation;

class NotifySubscribersOperation extends Operation
{
    private array $payload;

    public function __construct(array $payload)
    {
        $this->payload = $payload;
    }

    public function handle(): void
    {
        $this->runInQueue(new NotifyViaEmailJob($this->payload));
        
        $this->runInQueue(new NotifyViaPushNotificationJob($this->payload));
    }
}