PHP code example of singlephon / hotification

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

    

singlephon / hotification example snippets


'providers' => [
    # ...
    Singlephon\Hotification\HotificationServiceProvider::class,
],
'aliases' => [
    # ...
    'Hotification' => \Singlephon\Hotification\Hotification::class,
]

use Singlephon\Hotification\Extras\HotificationSender;
use App\Models\User;

(new Hotification())
    ->notify(User::find(1))
    ->icon('exclamation-triangle')
    ->title('Important notification...')
    ->description('Some description...')
    ->url('/app/friends/invitations')
    ->actionable()
    ->send();

'models' => [
    # Models for which observers need to be registered
],
'scheduled_notifications' => [
    # Settings for scheduled notifications
]


'models' => [

    \App\Models\Post::class => [
        # Send a notification when a new post is created
        'onCreated' => [
            \App\Notifications\PostCreatedNotification::class, # Should extend Singlephon\Hotification\Notifications\AbstractHotification
            function (Post $post) {
                # Callback to execute custom logic when a post is created
                # For example, sending a Push notification, logging, or modifying other properties
            },
        ],
        # Send a notification when a post is updated
        'onUpdated' => [
            \App\Notifications\PostUpdatedNotification::class,
        ]
    ],

    \App\Models\User::class => [
        'onCreated' => [
            function (User $user) {
                # Callback for executing logic when a new user is created
                # For example, sending a welcome message or logging activity
                (new Hotification())
                    ->notify($user)
                    ->icon('check-badge')
                    ->title('Welcome ' . $user->name)
                    ->description('Please continue registration form...')
                    ->url('/app/registration/continue')
                    ->actionable()
                    ->send();
            },
        ],
        # Send a notification when a user is deleted
        'onDeleted' => [
            \App\Notifications\ByeByeNotification::class,
            function (User $user) {
                # Callback for executing logic when a user is deleted
                # For example, sending a notification to the administrator
            }
        ]
    ]

]


'scheduled_notifications' => [
    'weekly_report' => function (Schedule $schedule) {
        $schedule->call(function () {
            (new Hotification())
                ->notify(User::all())
                ->icon('check-badge')
                ->title('Welcome ' . $user->name)
                ->description('Please continue registration form...')
                ->url('/app/registration/continue')
                ->actionable()
                ->send();
        })->everyWeek(); # Runs every week
    },
],
'daily_report' => [
    'events' => [
        \App\Notifications\DailyReportNotification::class, # Sending a notification
        function () {
            # Logic for executing a custom action
            # For example, generating a report and sending it via email
        },
    ],
    'schedule' => '0 0 * * *', # Every day at midnight
],


(new Hotification())
    ->manager()
    ->add(User::class,
        onUpdated: [function (User $user) {}],
        onCreated: [function (User $user) {}],
        onDeleted: [function (User $user) {}]
    );

bash
php artisan hotification:install