laravel 使用已有数据库自动创建model

1.laravel 使用已有数据库自动创建model
php artisan make:command create_model


app/Console/Console/Commands\create_model.php
protected $signature = 'my:create_model';
    public function handle()
    {
        $tables = DB::select(DB::raw('show tables'));
        foreach ($tables as $table) {
            foreach ($table as $v) {
                $table_names[] = $v;
                $this->call('make:model', ['name'=>$v]);
            }
        }
    }
   
app/Console/Console/Kernel.php
    protected $commands = [
        Commands\create_model::class
    ];

posted on 2016-09-05 13:38  anjuncc  阅读(510)  评论(0编辑  收藏  举报

导航