可以覆盖包提供的事件吗?
例如
通过composer安装到供应商目录中的包"laravel/cashier-mollie“有一个事件laravel\cashier-mollie\src\Events\OrderPaymentFailed
我想要做的是在这个事件被触发时更新数据库中的一个特定字段。
有什么想法吗?
发布于 2020-01-07 00:13:34
您可以在app/Providers/EventServiceProvider.php
中为事件添加自己的监听器
<?php
namespace App\Providers;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
use Laravel\Cashier\Events\OrderPaymentFailed;
use App\Listeners\OrderPaymentsFailedListener;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
OrderPaymentFailed::class => [
// Your custom listener
OrderPaymentsFailedListener::class,
],
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
parent::boot();
//
}
}
https://stackoverflow.com/questions/59615173
复制相似问题