Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel重写包事件_Laravel_Composer Php - Fatal编程技术网

Laravel重写包事件

Laravel重写包事件,laravel,composer-php,Laravel,Composer Php,是否可以覆盖程序包提供的事件 比如说 通过composer安装到供应商目录中的包“laravel/cashier mollie”有一个事件laravel\cashier mollie\src\Events\OrderPaymentFailed 我要做的是在触发此事件时更新数据库中的特定字段 有什么想法吗?您可以在app/Providers/EventServiceProvider.php <?php namespace App\Providers; use Illuminate\Aut

是否可以覆盖程序包提供的事件

比如说

通过composer安装到供应商目录中的包“laravel/cashier mollie”有一个事件laravel\cashier mollie\src\Events\OrderPaymentFailed

我要做的是在触发此事件时更新数据库中的特定字段


有什么想法吗?

您可以在
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();

        //
    }
}


您可以在
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();

        //
    }
}


您可以创建一个扩展此事件的新事件,例如
类MyCustomEvent Extendes OrderPaymentFailed
,然后连接到现有功能以执行某些操作。您可以创建一个扩展此事件的新事件,例如
类MyCustomEvent Extendes OrderPaymentFailed
,然后连接到现有的功能中去做一些事情。