PHP code example of tkrnx / laravel-teams-notifier

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

    

tkrnx / laravel-teams-notifier example snippets


use Tkrnx\LaravelTeamsNotifier\Facades\TeamsNotifier;

TeamsNotifier::info(
    title: 'Order Created',
    message: 'A new order has been created.',
    context: [
        'order_id' => 123,
        'total' => 1500,
    ],
);

TeamsNotifier::warning(
    title: 'Reward Stock Low',
    message: 'Reward stock is below threshold.',
    context: [
        'reward_id' => 10,
        'remaining_stock' => 3,
    ],
);

try {
    $service->run();
} catch (Throwable $exception) {
    TeamsNotifier::error(
        title: 'Operation Failed',
        message: 'The operation could not be completed.',
        context: [
            'entity_id' => 123,
            'event' => 'operation.failed',
        ],
        exception: $exception,
    );

    throw $exception;
}

TeamsNotifier::exception(
    exception: $exception,
    context: [
        'event' => 'operation.failed',
        'entity_id' => 123,
    ],
);

TeamsNotifier::exception(
    exception: $exception,
    context: ['entity_id' => 123],
    title: 'Entity Processing Failed',
);

use Tkrnx\LaravelTeamsNotifier\Contracts\TeamsNotifierContract;

final class ProcessEntity
{
    public function __construct(
        private readonly TeamsNotifierContract $notifier,
    ) {}

    public function handle(): void
    {
        $this->notifier->info('Entity Processed');
    }
}

use Illuminate\Support\Facades\Http;
use Tkrnx\LaravelTeamsNotifier\Facades\TeamsNotifier;

Http::fake([
    '*' => Http::response('', 202),
]);

TeamsNotifier::info('Test Notification');

Http::assertSentCount(1);
bash
php artisan vendor:publish --tag=teams-notifier-config
bash
php artisan vendor:publish \
  --provider="Tkrnx\LaravelTeamsNotifier\TeamsNotifierServiceProvider" \
  --tag="teams-notifier-config"
bash
php artisan queue:work