1
0
Fork 0
owl-admin-starter/app/Console/Commands/ResourceFill.php

46 lines
1.0 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Schema;
class ResourceFill extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'resource:fill {name}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'print resource column';
/**
* Execute the console command.
*/
public function handle()
{
$name = $this->argument('name');
$columns = [];
if (class_exists("App\\Models\\{$name}")) {
$model = app("App\\Models\\{$name}");
$columns = $model->getFillable();
}
if (Schema::hasTable($name)) {
$columns = Schema::getColumnListing($name);
}
if (count($columns) <= 0) {
return $this->error("{$name} 不存在");
}
foreach($columns as $key) {
$this->info("'{$key}' => \$this->{$key},");
}
}
}