From 97329aeec05e1c6f4dd68b1a5dd42b2b6bd85292 Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Fri, 1 Dec 2023 09:30:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20app/Console/ModelFillable.?= =?UTF-8?q?php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/ModelFillable.php | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 app/Console/ModelFillable.php diff --git a/app/Console/ModelFillable.php b/app/Console/ModelFillable.php new file mode 100644 index 0000000..c193e33 --- /dev/null +++ b/app/Console/ModelFillable.php @@ -0,0 +1,54 @@ +argument('table'); + $ignore = ['id', 'created_at', 'updated_at', 'deleted_at']; + $connection = $this->option('connection'); + if (! $connection) { + $connection = config('database.default'); + } + + if (Schema::connection($connection)->hasTable($table)) { + $list = Schema::connection($connection)->getColumnListing($table); + $list = array_filter($list, function ($value) use ($ignore) { + return ! in_array($value, $ignore); + }); + $this->info("protected \$fillable = ['".implode('\', \'', $list)."'];"); + } + } +}