Skip to content

Feature ​

You can generate a feature by running the following command.

bash
php artisan better:feature StoreBlog Blog

INFO

Generated feature will be at app/Modules/BlogModule/Features/StoreBlogFeature.php

Arguments ​

  • feature — name of the generated feature file (Feature is appended when missing)
  • module — name of the module where the feature will be generated (Module is appended when missing)

Options ​

Running jobs ​

WARNING

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

MethodAcceptsReturns
run(Job|Operation $unit)A Cores\Job or Cores\Operation instanceWhatever the unit's handle method returns
runInQueue(QueueableJob $unit, string $queue = 'default')A Cores\QueueableJob instanceIlluminate\Foundation\Bus\PendingDispatch

Units are passed as instances; class names are not accepted.

php
use App\Domains\Blog\Jobs\StoreBlogJob;
use App\Domains\Blog\Requests\StoreBlogRequest;
use App\Models\Blog;
use Laranex\BetterLaravel\Cores\Feature;

class StoreBlogFeature extends Feature
{
    public function handle(StoreBlogRequest $request): Blog
    {
        return $this->run(new StoreBlogJob($request->validated()));
    }
}

Running queue jobs ​

php
use App\Domains\Blog\Jobs\NotifyViaEmailJob;

class StoreBlogFeature extends Feature
{
    public function handle(StoreBlogRequest $request): Blog
    {
        $blog = $this->run(new StoreBlogJob($request->validated()));

        $this->runInQueue(new NotifyViaEmailJob($blog));
        // Or on a named queue
        $this->runInQueue(new NotifyViaEmailJob($blog), 'emails');

        return $blog;
    }
}

Running operations ​

php
use App\Modules\BlogModule\Operations\NotifySubscribersOperation;

class StoreBlogFeature extends Feature
{
    public function handle(StoreBlogRequest $request): Blog
    {
        $blog = $this->run(new StoreBlogJob($request->validated()));

        $this->run(new NotifySubscribersOperation($blog));

        return $blog;
    }
}

Released under the MIT License, except where a package says otherwise.