我正在尝试处理laravel作业后调用某些函数,并且我的代码与“文档”页面上的示例一样,但是我得到未定义的变量事件错误。
<?php
namespace App\Providers;
use App\Mail\EmailProcessed;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Queue;
use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Support\Facades\Log;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public $event;
public function boot()
{
Queue::before(function (JobProcessing $event) {
Log::info($event->job->resolveName());
});
Queue::after(function (JobProcessed $event) {
Log::notice($event->job->resolveName());
});
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
我收到此错误
[2019-01-30 14:08:55] local.ERROR: Undefined variable: event
{"exception":"[object] (ErrorException(code: 0): Undefined
variable: event at /var/www/html/email-verification-
app/app/Providers/AppServiceProvider.php:27)
答案 0 :(得分:0)
您应该删除一堆代码:
/**
* Bootstrap any application services.
*
* @return void
*/
public $event;