store-manage/app/Console/Commands/ModelFillable.php

55 lines
1.3 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} {--connection}';
/**
* 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'];
$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)."'];");
}
}
}