PHP code example of fntneves / laravel-transactional-events
1. Go to this page and download the library: Download fntneves/laravel-transactional-events library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fntneves / laravel-transactional-events example snippets
// Ensure the original EventServiceProvider is registered first, otherwise your event listeners are overriden.
$app->register(App\Providers\EventServiceProvider::class);
$app->configure('transactional-events');
$app->register(Neves\Events\EventServiceProvider::class);
namespace App\Events;
use Illuminate\Queue\SerializesModels;
use Illuminate\Foundation\Events\Dispatchable;
...
use Neves\Events\Contracts\TransactionalEvent;
class TicketsOrdered implements TransactionalEvent
{
use Dispatchable, InteractsWithSockets, SerializesModels;
...
}
DB::transaction(function () {
...
Event::dispatch(new TransactionalClosureEvent(function () {
// Job will be dispatched only if the transaction commits.
ProcessOrderShippingJob::dispatch($order);
});
...
});