Php 将Laravel事件/侦听器与Nova按钮一起使用

Php 将Laravel事件/侦听器与Nova按钮一起使用,php,laravel,laravel-nova,Php,Laravel,Laravel Nova,我想使用模块,但在其示例中,它显示了如何将按钮用于事件,但只显示了其侦听器。我很难理解他是如何定义他的钥匙的 下面是我的听众: <?php namespace App\Listeners; use App\Events\DeleteProduct; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; class DeleteProductListener {

我想使用模块,但在其示例中,它显示了如何将按钮用于事件,但只显示了其侦听器。我很难理解他是如何定义他的钥匙的

下面是我的听众:

<?php

namespace App\Listeners;

use App\Events\DeleteProduct;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class DeleteProductListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  DeleteProduct  $event
     * @return void
     */
    public function handle(DeleteProduct $event)
    {
        if ($event->key == 'mark-as-confirmed') {
            $event->resource->status = 1;
            $event->resource->save();
        }
    }
}
这是我点击按钮时的错误:

如何正确设置密钥?

请尝试以下操作:

在类中修改
EventServiceProvider

protected$listen=[
'\NovaButton\Events\button单击'=>[
“\App\Listeners\DeleteProductListener”
]
];
参考:

Button::make('Supprimer', 'mark-as-confirmed')
                ->event('App\Events\DeleteProduct')
                ->confirm('Êtes vous sûr de vouloir supprimer ce produit?')
                ->loadingText('Suppression...')
                ->successText('Supprimé!')