laravel fcm 2 code example
Example: laravel firebase cloud messaging notifications
composer require laravel-notification-channels/fcm:~2.0
class AccountActivated extends Notification
{
public function via($notifiable)
{
return [FcmChannel::class];
}
public function toFcm($notifiable)
{
return FcmMessage::create()
->setData(['data1' => 'value', 'data2' => 'value2'])
->setNotification(\NotificationChannels\Fcm\Resources\Notification::create()
->setTitle('Account Activated')
->setBody('Your account has been activated.')
->setImage('http://example.com/url-to-image-here.png'))
->setAndroid(
AndroidConfig::create()
->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics'))
->setNotification(AndroidNotification::create()->setColor('#0A0A0A'))
)->setApns(
ApnsConfig::create()
->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios')));
}
}
class User extends Authenticatable
{
use Notifiable;
public function routeNotificationForFcm()
{
return $this->fcm_token;
}
}
$user->notify(new AccountActivated);