【问题标题】:Method increments doesn't found in class. Laravel在类中找不到方法增量。拉拉维尔
【发布时间】:2015-03-04 12:06:35
【问题描述】:

那里。我正在尝试处理 Laravel 框架,但是有一个问题。这是我的代码

public function up()
    {
        Schema::create('users', function($table)
        {
            $table->increments('id');
        });
    }

我进行了迁移并尝试向我的表中添加一些字段。但是 IDE 不能正确识别 $table 变量,因此我有警告:“在类中找不到方法增量”,我不能使用自动完成。

有没有建议如何解决这个问题?

完整代码:

<?php

使用 Illuminate\Database\Schema\Blueprint; 使用 Illuminate\Database\Migrations\Migration;

类 CreatePostsTable 扩展迁移 {

public function up()
{
    Schema::create('posts', function($table)
    {
        $table->increments('id');
        $table->string('title',150);
        $table->text('body');
        $table->string('preview',300);
        $table->string('author',100);
        $table->timestamps();
    });
}


public function down()
{
    Schema::drop('posts');
}

}

【问题讨论】:

  • 你是如何运行这段代码的?您可以向我们发送更多您的代码吗?因为您的代码乍一看似乎很完美。
  • 它工作得很好,但是当我没有自动完成时,它真的很难编码

标签: php laravel schema


【解决方案1】:

只需指定$table 的类型。班级是Illuminate\Database\Schema\Blueprint

Schema::create('users', function(Blueprint $table)
{
    $table->increments('id');
});

【讨论】:

  • 什么意思?看看我提供的代码,还需要什么?
  • 哦,对不起。没注意这个蓝图 $table 非常感谢!
猜你喜欢
  • 2019-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-19
  • 2014-09-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多