PHP code example of okaufmann / laravel-notification-log
1. Go to this page and download the library: Download okaufmann/laravel-notification-log 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/ */
okaufmann / laravel-notification-log example snippets
return [
/*
|--------------------------------------------------------------------------
| Resolve Notification Message
|--------------------------------------------------------------------------
|
| If this is enabled, the Logger will try to resolve the built message
| out of the notification. This is useful if you want to debug your
| sent notifications.
|
*/
'resolve_notification_message' => env('NOTIFICATION_LOG_RESOLVE_NOTIFICATION_MESSAGE', false),
];
use Okaufmann\LaravelNotificationLog\Contracts\ShouldLogNotification;use Okaufmann\LaravelNotificationLog\Models\Concerns\LogsNotifications;
class DummyNotification extends Notification implements ShouldLogNotification
{
use LogsNotifications;
// ...
}
use Okaufmann\LaravelNotificationLog\Contracts\ShouldLogNotification;
use Okaufmann\LaravelNotificationLog\Contracts\ResolveMessageForLogging;
use Okaufmann\LaravelNotificationLog\Models\Concerns\LogsNotifications;
class CustomNotification extends Notification implements ShouldLogNotification, ResolveMessageForLogging
{
use LogsNotifications;
public function resolveMessageForLogging(string $channel, $notifiable): string
{
$channelName = get_class($channel);
$notifiableName = get_class($notifiable);
return "Custom message for {$channelName} channel sent to {$notifiableName}";
}
}
use Okaufmann\LaravelNotificationLog\Contracts\ShouldLogNotification;
use Okaufmann\LaravelNotificationLog\Contracts\ResolveMessageForLoggingAfterSent;
use Okaufmann\LaravelNotificationLog\Models\Concerns\LogsNotifications;
class WhatsAppNotification extends Notification implements ShouldLogNotification, ResolveMessageForLoggingAfterSent
{
use LogsNotifications;
public function resolveMessageForLoggingAfterSent(mixed $channel, $notifiable, $response): ?string
{
// Extract the actual message content from the WhatsApp API response
if (isset($response['message_id'])) {
return "WhatsApp message sent with ID: {$response['message_id']}";
}
return null;
}
}