Sometimes we need to change our column length in laravel migration. So in this tutorial, I am going to share laravel migration increase column size. We can do it manually but in this example, I will use the doctrine/dbal composer package.

You know that the default string length value is varchar(255). But we can change it. So let's assume we have a posts table and we need to change the title column length. 

<?php

use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->string('slug')->unique();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('posts');
    }
};

 

Now install the composer package by running the below command:

composer require doctrine/dbal

 

Now update the migration file to laravel migration integer length.

<?php

use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->id();
            $table->string('title',500)->change();
            $table->string('slug')->unique();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('posts');
    }
};

 

Now run php artisan migrate to check the changes.

 

Read also: How To Add Column After Specific Column In Laravel Migration

 

Conclusion

I have tried to discuss the clear concept of laravel migration integer length. Now we know laravel migration increase column size. Hope this change column length laravel migration tutorial will help you.