6
0
Fork 0
jiqu-library-server/app/Console/Commands/ModelFillable.php

52 lines
1.1 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
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');
$ignore = ['id', 'created_at', 'updated_at', 'deleted_at'];
if (Schema::hasTable($table)) {
$list = Schema::getColumnListing($table);
$list = array_filter($list, function ($value) use ($ignore) {
return !in_array($value, $ignore);
});
$this->info("protected \$fillable = ['".implode('\', \'', $list)."'];");
}
}
}