4
0
Fork 0
vine_liutk 2022-08-10 15:02:09 +08:00
commit f90cdc1e78
4 changed files with 57 additions and 2 deletions

View File

@ -9,7 +9,6 @@ use Peidikeji\Goods\Filters\GoodsFilter;
class Goods extends Model
{
use SoftDeletes;
use Filterable;
protected $table = 'goods';

View File

@ -65,7 +65,6 @@ class CreateGoodsTable extends Migration
$table->json('spec')->nullable()->comment('规格[{name, values: [{name, value}]}]');
$table->json('part')->nullable()->comment('配件[{name, values: [{name, value}]}]');
$table->timestamps();
$table->softDeletes();
$table->foreign('category_id')->references('id')->on('goods_category');
$table->foreign('type_id')->references('id')->on('goods_type');

View File

@ -49,6 +49,7 @@ class AdminServiceProvider extends ServiceProvider
Console\ExtensionDiableCommand::class,
Console\ExtensionUpdateCommand::class,
Console\UpdateCommand::class,
Console\ModelFillable::class,
];
/**

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');
}
}
}