stafftastic/laravel-cloudevents

A reusable cloudevent system for laravel projects.

2.1.0 2023-03-23 12:30 UTC

This package is auto-updated.

Last update: 2024-04-23 14:42:40 UTC


README

A Laravel library to publish Illuminate Events to dapr.

Installation

Install the package:

composer require stafftastic/laravel-cloudevents

Usage

  1. Publish config file
php artisan vendor:publish --provider="stafftastic\LaravelCloudEvents\CloudEventServiceProvider"
  1. Create your applications context:
<?php

namespace App\Events;

use App\Models\User;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use stafftastic\CloudEvents\CloudEventable;
use stafftastic\CloudEvents\IsCloudEvent;

class UserCreated implements CloudEventable
{
    use Dispatchable;
    use InteractsWithSockets;
    use SerializesModels;
    use IsCloudEvent;

    /**
     * Create a new event instance.
     *
     * @param  \Domain\Users\Models\User  $user
     *
     * @return void
     */
    public function __construct(public User $user)
    {
    }

    public function getCloudEventType(): string
    {
        return 'com.stafftastic.users.created';
    }

    public function getCloudEventTopic(): string
    {
        return 'stafftastic';
    }

    public function toCloudEventData(): array
    {
        return [
            'user' => $this->user,
        ];
    }
}