use native Notification table and migration

This commit is contained in:
2026-03-28 16:03:18 +01:00
parent de0457c426
commit 93bfc19e6e
4 changed files with 5 additions and 67 deletions
-24
View File
@@ -1,24 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Notification extends Model
{
protected $fillable = [
'content',
'user_id',
];
public function users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(
User::class,
'notification_user',
'notification_id',
)
->withPivot('unread')
->withTimestamps();
}
}
-12
View File
@@ -57,16 +57,4 @@ class User extends Authenticatable
public function tasks() { public function tasks() {
return $this->belongsToMany(Task::class); return $this->belongsToMany(Task::class);
} }
public function notifications(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(
Notification::class,
'notification_user',
'user_id',
'notification_id',
)
->withPivot('unread')
->withTimestamps();
}
} }
@@ -1,29 +0,0 @@
<?php
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('notification_user', function (Blueprint $table) {
$table->id();
$table->foreignId('notification_id')->constrained()->onDelete('cascade');
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('notification_user');
}
};
@@ -12,9 +12,12 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::create('notifications', function (Blueprint $table) { Schema::create('notifications', function (Blueprint $table) {
$table->id(); $table->uuid('id')->primary();
$table->string('type');
$table->morphs('notifiable');
$table->text('data');
$table->timestamp('read_at')->nullable();
$table->timestamps(); $table->timestamps();
$table->string('content');
}); });
} }