如何循环生成迁移表

代码如下

foreach ($this->table_arr as $key=> $device) {
            Schema::create('rd_'.$key, function (Blueprint $table) {
                $table->id(); 
                $table->timestamps();
                //状态
            foreach ($device['status'] as $key1 =>  $value) {
                $table->tinyInteger($key1)->comment($value);
            }
                // 数据
                foreach ($device['data'] as $key1 =>  $value) {
                    $table->float($key1, 8, 2)->comment($value);
                }
                // 额定
                foreach ($device['rated'] as $key1 =>  $value) {
                    $table->char($key1, 40)->comment($value);
                }
            });     
        }
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
最佳答案

你代码里面 匿名函数 得 把变量 use 进去

function (Blueprint $table)  use $device 
3年前 评论
lingliyi (楼主) 3年前
讨论数量: 2

没看懂,你自己发的代码不能用吗?

3年前 评论
lingliyi (楼主) 3年前

你代码里面 匿名函数 得 把变量 use 进去

function (Blueprint $table)  use $device 
3年前 评论
lingliyi (楼主) 3年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!