Laravel 10.xのartisanの「make:listener」コマンドを解説します。
Description
新しいイベントリスナークラスを作成します。
Usage
php artisan make:listener [-e|--event [=EVENT]] [-f|--force] [--queued] [--test] [--pest] [--phpunit] [--] <name>Arguments
| 引数 | 必須 | 説明 |
|---|---|---|
| name | 必須 | イベントリスナー名 |
Options
| オプション | 省略形 | 必須 | 説明 |
|---|---|---|---|
| event | e | – | 待機しているイベントクラス |
| force | f | – | リスナーが既に存在する場合でもクラスを作成 |
| queued | – | – | イベントリスナーをキューに入れるべきことを示す |
| test | – | – | Listenerに付随するTestテストを生成 |
| pest | – | – | Listenerに付随するPestテストを生成 |
| phpunit | – | – | Listenerに付随するPHPUnitテストを生成 |
Examples
no options
php artisan make:listener Foo INFO Listener [app/Listeners/Foo.php] created successfully. <?php
namespace App\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class Foo
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}
/**
* Handle the event.
*/
public function handle(object $event): void
{
//
}
}Stub
10.x
| Option | Stub file name |
|---|---|
| – | listener-queued.stub |
| queued | listener.queued.stub |
| event | listener.typed.stub |
| queued + event | listener-queued-duck.stub |
11.x
| Option | Stub file name |
|---|---|
| – | listener.stub |
| queued | listener.queued.stub |
| event | listener-duck.stub |
| queued + event | listener.typed.queued.stub |
Source
10.x
framework/src/Illuminate/Foundation/Console/ListenerMakeCommand.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/ListenerMakeCommand.php at 11.x · laravel/framework
The Laravel Framework. Contribute to laravel/framework development by creating an account on GitHub.


コメント