1. Go to this page and download the library: Download devkandil/notifire 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/ */
use DevKandil\NotiFire\Facades\Fcm;
// Simple notification
$success = Fcm::withTitle('Hello')
->withBody('This is a test notification')
->sendNotification($fcmToken);
if ($success) {
// Notification sent successfully
}
// Advanced notification
$success = Fcm::withTitle('Hello')
->withBody('This is a test notification')
->withImage('https://example.com/image.jpg')
->withIcon('notification_icon')
->withColor('#FF5733')
->withSound('default')
->withPriority(MessagePriority::HIGH)
->withAdditionalData(['key' => 'value'])
->sendNotification($fcmToken);
if ($success) {
// Notification sent successfully
}
// Send to a single topic
$success = Fcm::withTitle('News Update')
->withBody('Breaking news just dropped!')
->sendToTopics('news');
// Send to multiple topics
$topics = ['users', 'updates'];
$success = Fcm::withTitle('Hello')
->withBody('This is a test notification')
->sendToTopics($topics);
use DevKandil\NotiFire\Contracts\FcmServiceInterface;
$fcm = app(FcmServiceInterface::class);
// Simple notification
$fcm->withTitle('Hello')
->withBody('This is a test notification')
->sendNotification($fcmToken);
// Advanced notification
$fcm->withTitle('Hello')
->withBody('This is a test notification')
->withImage('https://example.com/image.jpg')
->withIcon('notification_icon')
->withColor('#FF5733')
->withSound('default')
->withPriority(MessagePriority::HIGH)
->withAdditionalData(['key' => 'value'])
->sendNotification($fcmToken);
// Send to a single topic
$fcm->withTitle('News Update')
->withBody('Breaking news just dropped!')
->sendToTopics('news');
// Send to multiple topics
$topics = ['users', 'updates'];
$fcm->withTitle('Hello')
->withBody('This is a test notification')
->sendToTopics($topics);
POST /fcm/token
use DevKandil\NotiFire\Traits\HasFcm;
class User extends Model
{
use HasFcm;
}
// Get the FCM token
$user->getFcmToken();
// Update the FCM token
$user->updateFcmToken($token);
// Send a notification
$user->sendFcmNotification(
'Hello',
'This is a test notification',
[
'image' => 'https://example.com/image.jpg',
'sound' => 'default',
'click_action' => 'OPEN_ACTIVITY',
'icon' => 'notification_icon',
'color' => '#FF5733',
'data' => ['key' => 'value'],
'priority' => MessagePriority::HIGH
]
);
use DevKandil\NotiFire\Notifications\ExampleNotification;
// Send a notification with custom title and body
$user->notify(new ExampleNotification('Welcome', 'Thank you for joining us!'));
use DevKandil\NotiFire\FcmMessage;
use DevKandil\NotiFire\Enums\MessagePriority;
public function toFcm($notifiable)
{
return FcmMessage::create('New Message', 'You have a new message')
->image('https://example.com/image.jpg')
->sound('default')
->clickAction('OPEN_ACTIVITY')
->icon('notification_icon')
->color('#FF5733')
->priority(MessagePriority::HIGH)
->data([
'message_id' => $this->message->id,
'timestamp' => now()->toIso8601String(),
]);
}
public function via($notifiable)
{
return ['fcm'];
}
use DevKandil\NotiFire\Traits\HasFcm;
class User extends Model
{
use HasFcm;
}
$user->notify(new NewMessage($message));
use DevKandil\NotiFire\FcmMessage;
use DevKandil\NotiFire\Enums\MessagePriority;
public function toFcm($notifiable)
{
// Send to a single topic
return FcmMessage::create('Breaking News', 'This is breaking news!')
->toTopics('news')
->priority(MessagePriority::HIGH)
->image('https://example.com/news.jpg');
}
public function toFcm($notifiable)
{
// Send to users subscribed to either 'news' OR 'updates' topics
return FcmMessage::create('Important Update', 'This affects multiple groups')
->toTopics(['news', 'updates'])
->data(['action' => 'update_
// Since topics don't fcm', null)->notify(new TopicNotification());
// First, get the FCM service instance using one of these methods:
// Method 1: Using dependency injection
use DevKandil\NotiFire\Contracts\FcmServiceInterface;
$fcm = app(FcmServiceInterface::class);
// Method 2: Using the Facade
use DevKandil\NotiFire\Facades\Fcm;
$fcm = Fcm::build();
// The fromRaw method accepts a complete FCM message payload and returns the service instance
// allowing you to chain methods like send()
$response = $fcm->fromRaw([
'message' => [
'token' => 'device-token',
'notification' => [
'title' => 'Hello',
'body' => 'This is a test notification',
],
'android' => [
'priority' => 'high',
],
'data' => [
'key' => 'value',
],
],
])->send();
if (isset($response['name'])) {
// Notification sent successfully with message ID: $response['name']
}
// Send to a single topic using raw payload
$response = $fcm->fromRaw([
'message' => [
'topic' => 'news',
'notification' => [
'title' => 'Breaking News',
'body' => 'This is breaking news!',
],
'android' => [
'priority' => 'high',
],
],
])->send();
// Send to multiple topics using condition
$response = $fcm->fromRaw([
'message' => [
'condition' => "'news' in topics || 'updates' in topics",
'notification' => [
'title' => 'Important Update',
'body' => 'This affects multiple groups',
],
'data' => [
'action' => 'update_