You can generate a feature by following command.
php artisan better:feature StoreBlog Blog
INFO
Generated feature will be at app/Modules/BlogModule/Features/StoreBlogFeature.php
WARNING
Feature must extend the Better Laravel feature Laranex\BetterLaravel\Cores\Feature
to work with the run
or runInQueue
method.
Running jobs from a feature or an operation is straightforward using run
method.
use App\Domains\Blog\Jobs\StoreBlogJob;
use App\Domains\Blog\Requests\StoreBlogRequest;
use Laranex\BetterLaravel\Cores\Feature;
class StoreBlogFeature extends Feature
{
public function handle(StoreBlogRequest $request): Blog
{
return $this->run(StoreBlogJob::class, ['payload' => $request->validated()]);
//Or
return $this->run(new StoreBlogJob($request->validated()));
//Or
return $this->run(new StoreBlogJob(payload: $request->validated()));
}
}
Running queue jobs from a feature or an operation is straightforward using runInQueue
method.
use App\Domains\Blog\Jobs\StoreBlogJob;
use App\Domains\Blog\Requests\StoreBlogRequest;
use Laranex\BetterLaravel\Cores\Feature;
class StoreBlogFeature extends Feature
{
public function handle(StoreBlogRequest $request): Blog
{
$blog = $this->run(new StoreBlogJob($request->validated()));
$this->runInQueue(new NotifyViaEmailJob($blog));
return $blog;
}
}
An Operation can be run using the run
method.
use App\Domains\Blog\Jobs\StoreBlogJob;
use App\Domains\Blog\Requests\StoreBlogRequest;
use App\Models\Blog;
use App\Modules\BlogModule\Operations\NotifySubscribersOperation;
use Laranex\BetterLaravel\Cores\Feature;
class StoreBlogFeature extends Feature
{
public function handle(StoreBlogRequest $request): Blog
{
$blog = $this->run(new StoreBlogJob($request->validated()));
$this->run(new NotifySubscribersOperation($blog));
return $blog;
}
}