Home  >  Article  >  PHP Framework  >  Laravel can elegantly modify the default auto-increment ID start value!

Laravel can elegantly modify the default auto-increment ID start value!

藏色散人
藏色散人forward
2020-09-08 09:12:542758browse

The following tutorial column will introduce you to an iconic method added in Laravel 8. I hope it will be helpful to friends in need!

#Laravel 8 has added an iconic method that can elegantly modify the starting value of the auto-increment ID. Today Taylor Otwell officially announced this new feature on Twitter :

Laravel can elegantly modify the default auto-increment ID start value!

public function up(){
    Schema::create('posts', function (Blueprint $table) {
        $table->id()->startingValue(1200);
        ...

Although you can change the starting value of the auto-increment ID through various database platforms, you always need to enter a line of instructions to achieve it. With the startingValue method above, you can use a more "Laravel" approach to setting the starting value of the auto-incrementing ID.

For most applications, you may not need this, but if you don't want to start counting IDs from 1, this is a convenient option.

小声bb: For example, the reserved 4-digit QQ number?

Original text: https://laravel-news.com/laravel-auto-increment

The above is the detailed content of Laravel can elegantly modify the default auto-increment ID start value!. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete