Php 是否可以将tinyInteger或smallInteger添加到laravel ORM的增量中?

Php 是否可以将tinyInteger或smallInteger添加到laravel ORM的增量中?,php,orm,laravel,laravel-4,eloquent,Php,Orm,Laravel,Laravel 4,Eloquent,是否可以将该代码或类似的内容添加到laravel\Lightning\Database\Schema\Blueprint以用于迁移 public function incrementsTiny($column) { return $this->unsignedTinyInteger($column, true); } public function incrementsSmall($column) { return $this->unsignedSmallInteger

是否可以将该代码或类似的内容添加到laravel\Lightning\Database\Schema\Blueprint以用于迁移

public function incrementsTiny($column)
{
   return $this->unsignedTinyInteger($column, true);
}

public function incrementsSmall($column)
{
   return $this->unsignedSmallInteger($column, true);
}
场景:一些临时表并没有增长到很高,并且有一些有用的信息,或者只是一个不超过100行的小表,需要一些罕见的更新(添加或更改)。但有可能添加到框架中吗?有很多信息是很常见的,但有时有些表没有很多数据

因为对于增量,只需选择整数或大整数即可

导航到:laravel/vendor/laravel/framework/src/illumb/Database/Schema

打开:Blueprint.php

查找:

在此之后添加:

     /**
     * Create a new auto-incrementing tiny integer column on the table.
     *
     * @param  string  $column
     * @return \Illuminate\Support\Fluent
     */
    public function incrementsTinyInteger($column)
    {
        return $this->unsignedTinyInteger($column, true);
    }

    /**
     * Create a new auto-incrementing small integer column on the table.
     *
     * @param  string  $column
     * @return \Illuminate\Support\Fluent
     */
    public function incrementsSmallInteger($column)
    {
        return $this->unsignedSmallInteger($column, true);
    }

    /**
     * Create a new auto-incrementing medium integer column on the table.
     *
     * @param  string  $column
     * @return \Illuminate\Support\Fluent
     */
    public function incrementsMediumInteger($column)
    {
        return $this->unsignedMediumInteger($column, true);
    }
     /**
     * Create a new unsigned tiny integer column on the table.
     *
     * @param  string  $column
     * @param  bool  $autoIncrement
     * @param  bool  $unsigned
     * @return \Illuminate\Support\Fluent
     */
    public function unsignedTinyInteger($column, $autoIncrement = false)
    {
        return $this->tinyInteger($column, $autoIncrement, true);
    }

    /**
     * Create a new unsigned small integer column on the table.
     *
     * @param  string  $column
     * @param  bool  $autoIncrement
     * @param  bool  $unsigned
     * @return \Illuminate\Support\Fluent
     */
    public function unsignedSmallInteger($column, $autoIncrement = false)
    {
        return $this->smallInteger($column, $autoIncrement, true);
    }

    /**
     * Create a new unsigned medium integer column on the table.
     *
     * @param  string  $column
     * @param  bool  $autoIncrement
     * @param  bool  $unsigned
     * @return \Illuminate\Support\Fluent
     */
    public function unsignedMediumInteger($column, $autoIncrement = false)
    {
        return $this->mediumInteger($column, $autoIncrement, true);
    }
查找:

public function unsignedInteger($column, $autoIncrement = false)
    {
        return $this->integer($column, $autoIncrement, true);
    }
在此之后添加:

     /**
     * Create a new auto-incrementing tiny integer column on the table.
     *
     * @param  string  $column
     * @return \Illuminate\Support\Fluent
     */
    public function incrementsTinyInteger($column)
    {
        return $this->unsignedTinyInteger($column, true);
    }

    /**
     * Create a new auto-incrementing small integer column on the table.
     *
     * @param  string  $column
     * @return \Illuminate\Support\Fluent
     */
    public function incrementsSmallInteger($column)
    {
        return $this->unsignedSmallInteger($column, true);
    }

    /**
     * Create a new auto-incrementing medium integer column on the table.
     *
     * @param  string  $column
     * @return \Illuminate\Support\Fluent
     */
    public function incrementsMediumInteger($column)
    {
        return $this->unsignedMediumInteger($column, true);
    }
     /**
     * Create a new unsigned tiny integer column on the table.
     *
     * @param  string  $column
     * @param  bool  $autoIncrement
     * @param  bool  $unsigned
     * @return \Illuminate\Support\Fluent
     */
    public function unsignedTinyInteger($column, $autoIncrement = false)
    {
        return $this->tinyInteger($column, $autoIncrement, true);
    }

    /**
     * Create a new unsigned small integer column on the table.
     *
     * @param  string  $column
     * @param  bool  $autoIncrement
     * @param  bool  $unsigned
     * @return \Illuminate\Support\Fluent
     */
    public function unsignedSmallInteger($column, $autoIncrement = false)
    {
        return $this->smallInteger($column, $autoIncrement, true);
    }

    /**
     * Create a new unsigned medium integer column on the table.
     *
     * @param  string  $column
     * @param  bool  $autoIncrement
     * @param  bool  $unsigned
     * @return \Illuminate\Support\Fluent
     */
    public function unsignedMediumInteger($column, $autoIncrement = false)
    {
        return $this->mediumInteger($column, $autoIncrement, true);
    }

导航到:laravel/vendor/laravel/framework/src/illumb/Database/Schema/语法

打开:MySqlGrammar.php

查找:
protected$serials=array('biginger','integer')

更改为:
protected$serials=array('biginger','integer','tinyInteger','smallInteger','mediumInteger')

另外,在上面的同一个文件中,可以找到:

protected function typeTinyInteger(Fluent $column)
    {
        return 'tinyint(1)';
    }
改为:

protected function typeTinyInteger(Fluent $column)
    {
        return 'tinyint';
    }

如果有人知道如何扩展此文件并在laravel中配置使用,并且想分享操作方法,我将非常感谢。但我不知道如何在扩展这些文件后配置所有内容,我知道如何在laravel中配置这些文件。

您可以使用以下方法:

$table->tinyInteger('id')->unsigned()->autoIncrement();
您可以在illumb\Database\Schema\Blueprint.php中看到tinyInteger函数定义:

/**
 * Create a new tiny integer (1-byte) column on the table.
 *
 * @param  string  $column
 * @param  bool  $autoIncrement
 * @param  bool  $unsigned
 * @return \Illuminate\Support\Fluent
 */
public function tinyInteger($column, $autoIncrement = false, $unsigned = false)
{
    return $this->addColumn('tinyInteger', $column, compact('autoIncrement', 'unsigned'));
}

因此,您只需将第2个和第3个参数设置为true,就可以得到无符号自动递增非空主键。

这当然是可能的。只需转到源代码,看看其他数据类型是如何创建的,并添加您的方法,也许可以通过继承Blueprint类。但这真的有必要吗?你会为这项工作带来重大的、切实的变化吗?或者在github上向Taylor建议。Taylor说这个改变对他来说并不重要。我认为这应该是一个有说服力的选择。但我不会与他和其他人讨论为什么需要,我在github上完成了这个项目。我认为雄辩是一个很好的工具,但不像其他许多工具那样完整。我知道ORM背后的人想要提供DB可移植性,而要让一切正常工作,这简直是一场地狱。我喜欢拉威尔,但需要一些好的调整。我认为人们对应用程序的更改多于对数据库的更改,这就是为什么我更喜欢将数据库优化到特定的数据库,而不是提供可移植性;我要添加到您的解决方案中的唯一一件事是,最好将
Blueprint
类继承到
供应商
文件夹之外的单独目录中,以便在使用composer进行更新时不会被覆盖。我认为最好将这些代码作为加载项添加,而不是编辑原始文件。你知道我们怎么做吗?