PHP code example of satheez / laravel-message-contracts

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

    

satheez / laravel-message-contracts example snippets


use Satheez\MessageContracts\Contracts\MessageContract;

final class UserRegisteredV1Message extends MessageContract
{
    public static function contract(): string
    {
        return 'user.registered';
    }

    public static function version(): int
    {
        return 1;
    }

    public static function rules(): array
    {
        return [
            'user_id' => ['

'contracts' => [
    App\MessageContracts\UserRegisteredV1Message::class,
],

$message = UserRegisteredV1Message::message(
    payload: [
        'user_id' => 123,
        'email' => '[email protected]',
        'registered_at' => now()->toISOString(),
    ],
    meta: [
        'trace_id' => 'req-7f1c4c2a',
    ],
);

$json = $message->toJson();

use Satheez\MessageContracts\DTO\Message;

$message = Message::fromJson($json);
$message->validateOrFail();

$userId = $message->payload('user_id');
bash
php artisan vendor:publish --tag=message-contracts-stubs
bash
php artisan make:message-contract UserRegistered \
  --contract-version=1 \
  --contract=user.registered