Skip to content
qnnp

Eloquent ORM 自动建表新建字段

发布于: | 没有评论 | 分类:

public function __construct() {
  // TODO 初始化操作等
  parent::__construct();
  $this->initTable();
}

private function initTable() {
  // 建表处理缺失字段等
  // TODO 可以使用缓存来判断表和字段是否已创建
  $schema = Db::schema();
  if (!$schema->hasTable($this->table)) {
    $schema->create($this->table, function (Blueprint $table) {
      $table->bigIncrements('ID')->comment('ID');
      $table->string('username')->unique('username')->comment('用户名');
      $table->string('nickname')->nullable()->comment('昵称');
    });
  }
}

标签:

0 0 投票数
文章评分
订阅评论
提醒
guest
0 评论
内联反馈
查看所有评论

0
希望看到您的想法,请您发表评论x