PHP code example of haythem-bekir / laravel-discord-logger

1. Go to this page and download the library: Download haythem-bekir/laravel-discord-logger 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/ */

    

haythem-bekir / laravel-discord-logger example snippets


use Illuminate\Support\Facades\Schedule;

Schedule::command('discord-logger:daily-report')->dailyAt('08:00');

protected function schedule(Schedule $schedule): void
{
    $schedule->command('discord-logger:daily-report')->dailyAt('08:00');
}

use HaythemBekir\DiscordLogger\Application\DailyReport\GatherLogStatisticsAction;
use HaythemBekir\DiscordLogger\Application\DailyReport\BuildDailyReportAction;
use HaythemBekir\DiscordLogger\Application\DailyReport\SendDailyReportAction;
use Carbon\Carbon;

class CustomReportService
{
    public function __construct(
        private GatherLogStatisticsAction $gather,
        private BuildDailyReportAction $build,
        private SendDailyReportAction $send,
    ) {}

    public function sendWeeklyDigest(): void
    {
        $dates = collect(range(0, 6))->map(fn($days) => Carbon::now()->subDays($days));

        foreach ($dates as $date) {
            $stats = $this->gather->execute($date);
            $report = $this->build->execute($stats);
            $this->send->execute($report);
        }
    }
}

return [
    'daily_report' => [
        'enabled' => env('DISCORD_LOGGER_DAILY_REPORT_ENABLED', false),
        'webhook_url' => env('DISCORD_LOGGER_DAILY_REPORT_WEBHOOK_URL'),
        'time' => env('DISCORD_LOGGER_DAILY_REPORT_TIME', '08:00'),
        'timezone' => env('DISCORD_LOGGER_DAILY_REPORT_TIMEZONE', 'UTC'),
    ],

    'appearance' => [
        'username' => env('DISCORD_LOGGER_BOT_USERNAME', 'Laravel Logger'),
        'avatar_url' => env('DISCORD_LOGGER_BOT_AVATAR_URL'),
    ],

    'colors' => [
        'emergency' => 0xFF0000, // Red
        'alert'     => 0xFF3300, // Orange-Red
        'critical'  => 0xFF6600, // Orange
        'error'     => 0xFF9900, // Dark Orange
        'warning'   => 0xFFCC00, // Yellow
        'notice'    => 0x00CCFF, // Cyan
        'info'      => 0x0099FF, // Blue
        'debug'     => 0x999999, // Gray
    ],

    'environment_label' => env('DISCORD_LOGGER_ENVIRONMENT_LABEL', env('APP_ENV')),

    'log_viewer' => [
        'enabled' => env('DISCORD_LOGGER_LOG_VIEWER_ENABLED', true),
        'app_url' => env('DISCORD_LOGGER_APP_URL', env('APP_URL')),
    ],
];
bash
php artisan vendor:publish --tag=discord-logger-config

src/
├── Application/DailyReport/      # Use cases & DTOs
│   ├── GatherLogStatisticsAction.php
│   ├── BuildDailyReportAction.php
│   └── SendDailyReportAction.php
├── Domain/                        # Business logic & value objects
│   ├── Config/
│   └── ValueObjects/
├── Infrastructure/                # External integrations
│   └── Http/DiscordWebhookClient.php
└── Console/Commands/              # Artisan commands