From 9a7a0d504fd2e2c807c645b5537fd018699a3c49 Mon Sep 17 00:00:00 2001 From: Geriano Date: Fri, 14 Oct 2022 07:58:04 +0700 Subject: [PATCH] fix bug column text is can't have default value --- app/Models/Menu.php | 15 +++++++++++++++ .../2022_07_15_192421_create_menus_table.php | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/Models/Menu.php b/app/Models/Menu.php index a5ea59d..96c06f3 100644 --- a/app/Models/Menu.php +++ b/app/Models/Menu.php @@ -106,4 +106,19 @@ class Menu extends Model get: fn () => $this->counter_handler ? new $this->counter_handler : null, ); } + + /** + * @inheritdoc + */ + public static function boot() + { + parent::boot(); + static::bootTraits(); + + static::creating(function (Menu $menu) { + if (empty($menu->actives)) { + $menu->actives = []; + } + }); + } } diff --git a/database/migrations/2022_07_15_192421_create_menus_table.php b/database/migrations/2022_07_15_192421_create_menus_table.php index e14257e..6d61c8b 100644 --- a/database/migrations/2022_07_15_192421_create_menus_table.php +++ b/database/migrations/2022_07_15_192421_create_menus_table.php @@ -27,7 +27,9 @@ return new class extends Migration $table->unsignedTinyInteger('position'); $table->boolean('enable')->default(true); $table->boolean('deleteable')->default(true); - $table->longText('actives')->default('[]'); + $table->longText('actives') + ->nullable() + ->default(null); $table->timestamps(); $table->foreign('parent_id')