Member-only story
Mastering Laravel Push Notifications: Migrating from Legacy Firebase Cloud Messaging (FCM) to HTTP v1 API in Laravel 11
5 min readNov 24, 2024
Create Model with migration for User Notification
php artisan make:model UserDevice -m
Then, update the migration file with the following code:
<?php
use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('user_devices', function (Blueprint $table) {
$userTableName = (new User)->getTable();
$table->id();
$table->foreignId('user_id')->constrained($userTableName)->onDeleteCascade();
$table->string('token')->unique();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('user_devices');
}
};
Also, update the UserDevice file with the following code:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class UserDevice extends Model
{
protected $fillable = [
'user_id',
'token',
];
public function user()
{…