4
0
Fork 0

add commadn

master
panliang 2022-08-10 14:08:27 +08:00
parent 4265663701
commit 80245a9775
2 changed files with 56 additions and 1 deletions

@ -1 +0,0 @@
Subproject commit 2b3e329a33bea20dc39d5c869faf0fb8f7e96e4d

View File

@ -0,0 +1,56 @@
<?php
namespace Dcat\Admin\Console;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class ModelFillable extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'model:fillable {table}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'get model fillable ';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
*/
public function handle()
{
$table = $this->argument('table');
$except = ['id', 'created_at', 'updated_at'];
if (Schema::hasTable($table)) {
if (DB::getDefaultConnection() === 'mysql') {
$list = DB::table('information_schema.columns')->where(['table_schema' => config('database.connections.mysql.database'), 'table_name' => $table])->pluck('COLUMN_NAME')->all();
} else {
$list = Schema::getColumnListing($table);
}
$list = array_filter($list, fn($v) => !in_array($v, $except));
$this->info("protected \$fillable = ['".implode('\', \'', $list)."'];");
} else {
$this->error('table ' . $table . ' is not exists');
}
}
}