英文:
Laravel override a package event
问题
是否可以覆盖一个由包提供的事件?
例如
通过Composer安装到vendor目录的包"laravel/cashier-mollie"有一个事件laravel\cashier-mollie\src\Events\OrderPaymentFailed
我想要做的是当这个事件被触发时更新我的数据库中的特定字段。
有什么想法吗?
英文:
Is it possible to override a package provided event?
For example
Package "laravel/cashier-mollie" which is installed via composer into the vendor dir has an event laravel\cashier-mollie\src\Events\OrderPaymentFailed
What I want to do is update a specific field in my database when this event is fired.
Any ideas?
答案1
得分: 3
你可以在 app/Providers/EventServiceProvider.php
中为事件添加自定义监听器。
英文:
You can add your own Listener for the event in 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();
//
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论