From 2ba5cdca8f2607ed53ba00ed3122129861bcafbb Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Wed, 20 Sep 2023 00:04:16 -0600 Subject: [PATCH] fix: post table field types --- CHANGELOG.md | 1 + src/app/Http/Controllers/PostController.php | 4 +-- ...2023_09_20_055545_fix_post_field_types.php | 32 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/database/migrations/2023_09_20_055545_fix_post_field_types.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 6026f3e..36a4570 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Categories are now unique and required, enforced at the database level - Various database indexes were added for common lookup patterns for quick retrieval +- Fixes various database field types and type validation on form submission to better align with the context they are used with - Fixes a bug that didn't show the dropdown chevrons for form-select fields when creating a post - Fixes a Bootstrap deprecation warning - Updates MariaDB from 10.11 to 11.1 diff --git a/src/app/Http/Controllers/PostController.php b/src/app/Http/Controllers/PostController.php index d6ba3c8..989b839 100644 --- a/src/app/Http/Controllers/PostController.php +++ b/src/app/Http/Controllers/PostController.php @@ -166,7 +166,7 @@ public function create(Request $request): RedirectResponse }) ], 'keywords' => 'nullable|string', - 'category_id' => 'nullable|string', + 'category_id' => 'nullable|integer', 'post' => 'required|string', 'banner_image_url' => 'nullable|string', 'published' => 'required|integer', @@ -206,7 +206,7 @@ public function update(Request $request, int $id): RedirectResponse }) ], 'keywords' => 'nullable|string', - 'category_id' => 'nullable|string', + 'category_id' => 'nullable|integer', 'post' => 'required|string', 'banner_image_url' => 'nullable|string', 'published' => 'required|integer', diff --git a/src/database/migrations/2023_09_20_055545_fix_post_field_types.php b/src/database/migrations/2023_09_20_055545_fix_post_field_types.php new file mode 100644 index 0000000..01d78fc --- /dev/null +++ b/src/database/migrations/2023_09_20_055545_fix_post_field_types.php @@ -0,0 +1,32 @@ +integer('category_id')->change(); + $table->string('keywords')->change(); + $table->mediumText('post')->change(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('posts', function (Blueprint $table) { + $table->string('category_id')->change(); + $table->text('keywords')->change(); + $table->longText('post')->change(); + }); + } +};