我正在嘗試在 laravel 中創建一個帶有 --debug選項的 artisan 命令。要在整個類范圍內使用調試開關,我使用 __construct 并將其分配給類屬性。 public function __construct(){ parent::__construct(); $this->debug = $this->option('debug'); } 當我在 handle 方法中使用 $this->option('debug') 時沒有問題。但是當我在 __construct 中使用它時,我得到調用成員函數 getOption() on null {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Call to a member function getOption() on null at /Users/user /Sites/app/vendor/laravel/framework/src/Illuminate/Console/Command.php:310)我不確定,但看起來好像 option() 在構造時還沒有準備好。檢查了文檔,但找不到任何內容。有沒有人對此有所了解或我如何做到這一點?
- 1 回答
- 0 關注
- 170 瀏覽
添加回答
舉報
0/150
提交
取消