PHP code example of goldnead / statamic-notifications

1. Go to this page and download the library: Download goldnead/statamic-notifications 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/ */

    

goldnead / statamic-notifications example snippets


use Goldnead\Notifications\Facades\Notifications;

Notifications::notify($user, 'community.mention', [
    'message' => 'Bea hat dich erwähnt.',
    'link' => '/account/community/posts/'.$post->id,
    'dedupe_key' => 'mention:'.$mention->id,
]);

Notifications::unreadCount($user);
Notifications::markRead($item);

use Goldnead\Notifications\Facades\Notifications;

Notifications::notify($user, 'community.mention', [
    'actor' => $author,               // anything IdentityContext can resolve
    'subject' => $post,               // any Eloquent model
    'message' => 'Bea hat dich erwähnt.',
    'link' => '/account/community/posts/'.$post->id,
    'dedupe_key' => 'mention:'.$mention->id,
]);

Notifications::notifyMany($subscribers, 'lms.lesson_published', [
    'dedupe_key' => 'lesson:'.$lesson->id,   // scoped per recipient automatically
]);

Notifications::registerType('community.mention', function ($type) {
    $type->label('Erwähnung')
        ->defaultChannels(['in_app', 'mail'])
        ->renderUsing(fn ($item) => [
            'message' => $item->actor_name.' hat dich erwähnt.',
            'link' => '/account/community/posts/'.$item->subject_id,
        ]);
});

$preferences = app(PreferenceResolver::class);
$preferences->set($user, 'community.mention', 'mail', false);
$preferences->matrixFor($user);   // for a preference centre

Notifications::registerSource('community', CommunityDigestSource::class);

public function collect(Identity $recipient, Carbon $since, Carbon $until): array
{
    return $count === 0 ? [] : ['line' => "{$count} open replies."];
}

'realtime' => ['enabled' => true, 'channel_prefix' => 'users'],

public function via($notifiable): array { return ['notifications']; }

public function toNotifications($notifiable): array
{
    return ['type' => 'crm.lead_assigned', 'message' => '…', 'link' => '…'];
}
bash
composer migrate
php artisan vendor:publish --tag=notifications-config
bash
php artisan notifications:send-digests --frequency=weekly [--dry-run] [--now=…]
bash
php artisan notifications:uniqueness-integrity [--repair]