You can generate a feature by following command.
php artisan next:feature StoreBlog Blog
INFO
Generated feature will be at app/Modules/BlogModule/Features/StoreBlogFeature.php
WARNING
Feature must extend the Next Laravel feature Laranex\NextLaravel\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\Modules\BlogModule\Jobs\StoreBlogJob;
use App\Modules\BlogModule\Http\Requests\StoreBlogRequest;
use Laranex\NextLaravel\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\Modules\BlogModule\Jobs\StoreBlogJob;
use App\Modules\BlogModule\Http\Requests\StoreBlogRequest;
use Laranex\NextLaravel\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\Modules\BlogModule\Jobs\StoreBlogJob;
use App\Modules\BlogModule\Http\Requests\StoreBlogRequest;
use App\Models\Blog;
use App\Modules\BlogModule\Operations\NotifySubscribersOperation;
use Laranex\NextLaravel\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;
}
}