PHP code example of zein-api / firebase-notification

1. Go to this page and download the library: Download zein-api/firebase-notification 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/ */

    

zein-api / firebase-notification example snippets


'providers' => [
    // ...
    ZeinApi\FirebaseNotification\FirebaseNotificationServiceProvider::class,
],



namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use ZeinApi\FirebaseNotification\Traits\HasNotifications;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable, HasNotifications;
    
    // ... rest of your User model code
}

use ZeinApi\FirebaseNotification\Models\Notification;

// Create and send notification to a single user
$notification = Notification::create_notification(
    'notification_type',
    $source,  // The model that triggered the notification (optional)
    $target,  // The model that the notification is about (optional)
    [
        'key' => 'value',  // Additional data
    ]
);
$notification->send_to_user($user_id);

// Send to multiple users
$notification->send_to_users([$user_id1, $user_id2]);

// resources/lang/en/firebase-notification.php
return [
    'notification_type' => 'Your notification message with :parameter',
];

'providers' => [
    // ...
    ZeinApi\FirebaseNotification\FirebaseNotificationServiceProvider::class,
],
bash
php artisan vendor:publish --provider="ZeinApi\FirebaseNotification\FirebaseNotificationServiceProvider"
bash
php artisan migrate
bash
composer dump-autoload
bash
php artisan config:clear
php artisan cache:clear