Laravel Packages

Firebase Cloud Notifications for Laravel

Published
Firebase Cloud Notifications for Laravel image

The Syntech Firebase Cloud Messaging (FCM) package for Laravel makes it easy to use Laravel's notification system to send Firebase notifications. The use-case for FCM messages includes iOS and Android apps, web applications, flutter, and more:

namespace App\Notifications;
 
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
 
class YourNotification extends Notification
{
use Queueable;
 
public function via($notifiable)
{
return ['fcm'];
}
 
public function toFcm($notifiable)
{
return [
'to' => $notifiable->device_token,
'notification' => [
'title' => 'Notification Title',
'body' => 'Notification Body',
'image' => '', // Optional image URL
],
];
}
}
 
// Usage:
$user->notify(new YourNotification($title, $body));

The above example doesn't show that you need device tokens to send FCM notifications, so be sure to read the installation docs for complete setup.

Learn More

You can learn more about this package, get full installation instructions, and view the source code on GitHub. Also, check out Laravel's Notifications documentation to learn how easy Laravel makes sending notifications.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article