fix: make user id nullable

This commit is contained in:
2025-12-12 21:18:01 +03:30
parent be0abcb614
commit c4a05cc67c
2 changed files with 38 additions and 1 deletions
+1 -1
View File
@@ -120,7 +120,7 @@ public function packageStore(Request $request, PackageName $packageName)
$reminder = Reminder::create([
...$data,
'package_name_id' => $packageName->id,
'user_id' => Auth::id()
'user_id' => null
]);
return response()->json($reminder, 201);
@@ -0,0 +1,37 @@
<?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::table('reminders', function (Blueprint $table) {
// First, drop the foreign key constraint
$table->dropForeign(['user_id']);
// Make the column nullable
$table->foreignId('user_id')->nullable()->change();
// Re-add the foreign key constraint with nullable
$table->foreign('user_id')->references('id')->on('users')->onDelete('CASCADE');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('reminders', function (Blueprint $table) {
$table->dropForeign(['user_id']);
$table->foreignId('user_id')->change();
$table->foreign('user_id')->references('id')->on('users')->onDelete('CASCADE');
});
}
};