Skip to content

Operation

You can generate an operation by running the 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 will be generated

Options

Calling Jobs from an Operation

WARNING

Operation must extend Laranex\BetterLaravel\Cores\Operation to use the run or runInQueue methods.

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

class NotifySubscribersOperation extends Operation
{
    public function __construct(private array $payload) {}

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

Calling Queue Jobs from an Operation

php
class NotifySubscribersOperation extends Operation
{
    public function __construct(private array $payload) {}

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