0

我正在尝试在处理 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)
4

1 回答 1

0

你应该删除那一堆代码:

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public $event;
于 2019-01-30T14:48:31.950 回答