You can now easily change the default database auto increment value in Laravel

You can now easily change the default database auto increment value in Laravel

Laravel 8 adds a brand new method to make changing the auto-increment starting value easy, and here is the official announcement made on Twitter:

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

Changing the auto-increment through the various database platforms has always been possible, but you needed to do it via a raw command. With the addition of the startingValue method, this allows you to set the first number the auto-increment will start at in a fluent Laravel way.

For most apps, you will probably not need this but in those situations where you do not want a record starting at one, it’s a handy option.

Filed in: News / Eloquent / Migrations

Newsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Full-Stack Engineer
[REMOTE: USA Only] All Other Applications Will be Rejected Immediately"
Curricula
Senior Full Stack PHP Developer
Canada
Motto Design Studio
👉 Looking for Senior Back-End Laravel API Developer - Immediate (Full-time Contractor) 🎉
Remote
ApproveMe.com // The Document Signing Experience™
Senior Software Engineer
Remote or Los Angeles
Coverfly
Sr. Software Engineer
Salt Lake City, UT
Clearlink