1. Go to this page and download the library: Download mhd-elawi/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/ */
mhd-elawi / notification example snippets
'default_language' => 'en',
'languages' => ['en', 'ar', 'de', 'fr'],
'save_notifications' => true, // Set false to disable
'send_notifications' => true,
use MhdElawi\Notification\Utils\Notification;
Notification::for($user)
->setTitle('Hello, World!')
->setBody('This is a test notification.')
->send();
Notification::for($user)
->setTitle('Bonjour, Monde!', 'fr')
->setBody('Ceci est une notification de test.', 'fr')
->send();
Notification::for($users)
->setTitle('Batch Notification')
->setBody('This notification is sent to multiple users.')
->send();
$relatedModel = Post::query()->first();
Notification::for($user, $relatedModel)
->setTitle('New Comment on Your Post')
->setBody('Someone has commented on your post.')
->setIcon('comment-icon')
->send();
$relatedModel = Post::query()->first();
Notification::for($user)
->setRelatedModel($relatedModel) // Set the related model explicitly
->setTitle('New Comment on Your Post')
->setBody('Someone has commented on your post.')
->setIcon('comment-icon')
->send();
Notification::for($user)
->setTitle('New Comment on Your Post')
->setBody('Someone has commented on your post.')
->setIcon('comment-icon')
->setExtraFields(['sound' => 'something'])
->send();
use MhdElawi\Notification\Contracts\HasNotification;
class User extends Authenticatable implements HasNotification
{
public function getDeviceTokens(): array
{
return $this->device_tokens ?? [];
}
}