laravel-notification-channels / fcm

Firebase Cloud Messaging (FCM) notifications channel for Laravel
https://laravel-notification-channels.com/
MIT License
472 stars 121 forks source link

I cant send notification via fcm why ? #182

Closed lencls37 closed 6 months ago

lencls37 commented 7 months ago

I followed docs but it's not work..

CarNotification.php; `class CarNotifications extends Notification { use Queueable;

/**
 * Create a new notification instance.
 */
public function __construct()
{
}

public function fcmProject($notifiable, $message)
{
    // $message is what is returned by `toFcm`
    return 'app'; // name of the firebase project to use
}
/**
 * Get the notification's delivery channels.
 *
 * @return array<int, string>
 */
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'));
} `

User model; class User extends Authenticatable implements MustVerifyEmail { use HasApiTokens, HasFactory, Notifiable, HasPushSubscriptions; ..... public function routeNotificationForFcm() { return $this->getDeviceTokens(); } ...

NotificationSendBlade;

`new class extends Component {

public function sendNotification()
{
    $user = Auth::user();
    $user->notify(new CarNotifications());
}

}; ?>`

.env

FIREBASE_CREDENTIALS=storage/app/arabag-app-70184ee02367.json

dwightwatson commented 7 months ago

Looks like you're using an older version of the package. Could you please try again on the latest version?