PHP code example of saurabhpunia / notifyx

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

    

saurabhpunia / notifyx example snippets


// Send a simple notification
notify($user)
    ->title('Welcome!')
    ->with('Thanks for joining our platform')
    ->type('message')
    ->send();



namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Notifyx\Concerns\HasNotifyx;

class User extends Authenticatable
{
    use HasNotifyx; // Add this line
    
    // ... rest of your User model
}

'types' => [
    'message' => [
        'label' => 'Messages',
        'icon' => 'heroicon-o-chat-bubble-left-right',
        'color' => 'blue'
    ],
    'system' => [
        'label' => 'System Updates',
        'icon' => 'heroicon-o-cog-6-tooth',
        'color' => 'gray'
    ],
    'billing' => [
        'label' => 'Billing',
        'icon' => 'heroicon-o-currency-dollar',
        'color' => 'green'
    ],
],

// config/notifyx.php

'multitenant' => true,
'tenant_resolver' => fn() => auth()->user()->current_team_id,

notify($user)
    ->with('Your order has been shipped!')
    ->send();

notify($user)
    ->title('Order Update')
    ->with('Your order #12345 has been shipped and will arrive tomorrow.')
    ->send();

notify($user)
    ->title('Payment Received')
    ->with('We received your payment of $99.99')
    ->type('billing')
    ->send();

notify($user)
    ->title('New Message')
    ->with('You have a new message from John')
    ->type('message')
    ->action('/messages', 'View Message')
    ->send();

notify($user)
    ->title('Welcome!')
    ->with('Thanks for joining our platform')
    ->type('message')
    ->via(['database', 'mail', 'broadcast']) // Send via multiple channels
    ->send();

use Notifyx\Facades\Notifyx;

Notifyx::to($user)
    ->title('Hello!')
    ->with('This is a test notification')
    ->send();

// routes/web.php
Route::get('/notifications', function() {
    return view('notifications');
})->name('notifications.index');

'types' => [
    'order' => [
        'label' => 'Order Updates',
        'icon' => 'heroicon-o-shopping-bag',
        'color' => 'purple'
    ],
    'friend_request' => [
        'label' => 'Friend Requests',
        'icon' => 'heroicon-o-user-plus',
        'color' => 'pink'
    ],
],

// Get recent notifications
$notifications = $user->getNotifications(10);

// Get paginated notifications
$notifications = $user->getPaginatedNotifications(15);

// Get unread count
$unreadCount = $user->getUnreadCount();

// Mark notification as read
$user->markNotificationAsRead($notificationId);

// Mark all as read
$user->markAllNotificationsAsRead();

// Check if user has enabled email notifications for billing
if ($user->hasEnabledNotification('billing', 'mail')) {
    // Send billing notification via email
}
bash
php artisan vendor:publish --tag="notifyx-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="notifyx-config"
bash
php artisan vendor:publish --tag="notifyx-views"