Laravel 10.xのartisanの「make:job」コマンドを解説します。
Description
新しいジョブクラスを作成します。
Usage
php artisan make:job [-f|--force] [--sync] [--test] [--pest] [--] <name>
Arguments
引数 | 必須 | 説明 |
---|---|---|
name | 必須 | ジョブ名 |
Options
オプション | 省略形 | 必須 | 説明 |
---|---|---|---|
force | f | - | ジョブが既に存在する場合でもクラスを作成 |
sync | - | - | ジョブが同期的であることを示す |
test | - | - | Jobに付随するPHPUnitのテストを生成 |
pest | - | - | ジョブに付随するペストテストを生成 |
Examples
no options
php artisan make:job FooJob
INFO Job [app/Jobs/FooJob.php] created successfully.
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class FooJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*/
public function __construct()
{
//
}
/**
* Execute the job.
*/
public function handle(): void
{
//
}
}
sync
php artisan make:job --sync FooJob
INFO Job [app/Jobs/FooJob.php] created successfully.
<?php
namespace App\Jobs;
use Illuminate\Foundation\Bus\Dispatchable;
class FooJob
{
use Dispatchable;
/**
* Create a new job instance.
*/
public function __construct()
{
//
}
/**
* Execute the job.
*/
public function handle(): void
{
//
}
}
Stub
Option | Stub file name |
---|---|
- | job.stub |
sync | job.queued.stub |
Source
10.x
framework/src/Illuminate/Foundation/Console/JobMakeCommand.php at 10.x · laravel/framework
The Laravel Framework. Contribute to laravel/framework development by creating an account on GitHub.
11.x
framework/src/Illuminate/Foundation/Console/JobMakeCommand.php at 11.x · laravel/framework
The Laravel Framework. Contribute to laravel/framework development by creating an account on GitHub.
コメント