diff --git a/app/Actions/GetRecentLinks.php b/app/Actions/GetRecentLinks.php index 0f11e85..5a79392 100644 --- a/app/Actions/GetRecentLinks.php +++ b/app/Actions/GetRecentLinks.php @@ -24,7 +24,7 @@ public function handle(int $limit = 10): array 'title' => $link->title, 'description' => $link->description, 'category' => $link->category->value, - 'submitted_by' => $link->submittedBy->name, + 'submitted_by' => $link->submittedBy?->name ?? 'Anonymous', 'created_at' => $link->created_at->diffForHumans(), ]; }); diff --git a/database/migrations/2025_09_18_171819_add_delete_cascade_for_user_link_relations.php b/database/migrations/2025_09_18_171819_add_delete_cascade_for_user_link_relations.php new file mode 100644 index 0000000..916375d --- /dev/null +++ b/database/migrations/2025_09_18_171819_add_delete_cascade_for_user_link_relations.php @@ -0,0 +1,70 @@ +dropForeign(['submitted_by_user_id']); + $table->unsignedBigInteger('submitted_by_user_id')->nullable()->change(); + $table->foreign('submitted_by_user_id')->references('id')->on('users')->onDelete('set null'); + }); + + Schema::table('user_links', function (Blueprint $table) { + $table->dropForeign(['user_id']); + $table->dropForeign(['link_id']); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->foreign('link_id')->references('id')->on('links')->onDelete('cascade'); + }); + + Schema::table('link_notes', function (Blueprint $table) { + $table->dropForeign(['user_id']); + $table->dropForeign(['link_id']); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->foreign('link_id')->references('id')->on('links')->onDelete('cascade'); + }); + + Schema::table('user_statuses', function (Blueprint $table) { + $table->dropForeign(['link_id']); + $table->foreign('link_id')->references('id')->on('links')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('links', function (Blueprint $table) { + $table->dropForeign(['submitted_by_user_id']); + $table->unsignedBigInteger('submitted_by_user_id')->nullable(false)->change(); + $table->foreign('submitted_by_user_id')->references('id')->on('users'); + }); + + Schema::table('user_links', function (Blueprint $table) { + $table->dropForeign(['user_id']); + $table->dropForeign(['link_id']); + $table->foreign('user_id')->references('id')->on('users'); + $table->foreign('link_id')->references('id')->on('links'); + }); + + Schema::table('link_notes', function (Blueprint $table) { + $table->dropForeign(['user_id']); + $table->dropForeign(['link_id']); + $table->foreign('user_id')->references('id')->on('users'); + $table->foreign('link_id')->references('id')->on('links'); + }); + + Schema::table('user_statuses', function (Blueprint $table) { + $table->dropForeign(['link_id']); + $table->foreign('link_id')->references('id')->on('links')->onDelete('set null'); + }); + } +}; diff --git a/resources/js/components/delete-user.tsx b/resources/js/components/delete-user.tsx index 7c4b73a..fa03993 100644 --- a/resources/js/components/delete-user.tsx +++ b/resources/js/components/delete-user.tsx @@ -40,25 +40,8 @@ export default function DeleteUser() { resetOnSuccess className="space-y-6" > - {({ resetAndClearErrors, processing, errors }) => ( + {({ resetAndClearErrors, processing }) => ( <> -
- - - - - -
-