使用 Laravel Events/Listener 和 Nova 按钮

Use Laravel Events/Listener with Nova buttons

我想使用 https://github.com/dillingham/nova-button 模块,但在其示例中,它显示了如何将按钮与事件一起使用,但仅显示其侦听器。我很难理解他是如何定义他的密钥的。

这是我的听众:

<?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();
        }
    }
}

这是我的新星场:

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

这是我点击按钮时的错误:

如何正确设置密钥?

试试这个:

修改你的classEventServiceProvider

protected $listen = [
    '\NovaButton\Events\ButtonClick' => [
        '\App\Listeners\DeleteProductListener'
    ]
];

参考:https://github.com/dillingham/nova-button/issues/9#issuecomment-457760978