PHP code example of lifespikes / expo-notification-channel
1. Go to this page and download the library: Download lifespikes/expo-notification-channel 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/ */
lifespikes / expo-notification-channel example snippets
class NotifiableModel extends Model {
// You may pass a single token
public function routeNotificationForExpo($notification)
{
return "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]"
}
// Or you may return an array of tokens, for example, a user could have multiple devices.
public function routeNotificationForExpo($notification)
{
return $this->installations->pluck('expo_token')->toArray()
}
}
namespace App\Notifications;
use App\Models\Message;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use NotificationChannels\Expo\ExpoChannel;
use NotificationChannels\Expo\ExpoMessage;
class NewMessageNotification extends Notification
{
use Queueable;
private Message $message;
public function __construct(Message $message)
{
$this->message = $message;
}
public function via($notifiable)
{
return [ExpoChannel::class];
}
public function toExpo($notifiable)
{
return ExpoMessage::create()
->title("New Message from {$this->message->from}!")
->body($this->message->text)
->badge(1);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.