Closed acedesigns closed 2 years ago
You need to create a new Notification class that extends notification (i.e. AccountActivated). You can do this via php artisan make:notification
Then, in that class you have to implement the "via" method and "toFcm" method like below from the instructions. Then, once you have that setup, then you call the notify method on the User passing in the new Notification class like so... $user->notify(new AccountActivated);
++++++
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')));
}
@acedesigns Have you followed all the steps documented in the README? have you followed all the steps documented in: https://github.com/kreait/laravel-firebase?
Cheers,
You need to create a new Notification class that extends notification (i.e. AccountActivated). You can do this via php artisan make:notification
Then, in that class you have to implement the "via" method and "toFcm" method like below from the instructions. Then, once you have that setup, then you call the notify method on the User passing in the new Notification class like so... $user->notify(new AccountActivated);
++++++
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'))); }
Then how you define the recipient of the notification? still does not make sense to me
You call the notification like so: $recipient->notify(new AccountActivated);
. You do not have to define the recipient in the notification itself.
Hi All.
So I ha a dashboard that I created with AdminLTE. So now I want to send a person a notification when I click on a button. This may be. a silly question/PR but I can not get it to work.
I am unable to figure out how to implement this to work. The ReadMe is not understandable to me
This is the function that runs when I click on that button
I was able to send and receive the notification when testing using Firebase on the browser
My User.php