PHP code example of stafftastic / laravel-cloudevents

1. Go to this page and download the library: Download stafftastic/laravel-cloudevents 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/ */

    

stafftastic / laravel-cloudevents example snippets




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,
        ];
    }
}
bash
php artisan vendor:publish --provider="stafftastic\LaravelCloudEvents\CloudEventServiceProvider"