How to Increase Column Size using Laravel Migration?

10-Apr-2023

.

Admin

Hi Guys,

In this tutorial,I will learn you how to change length using laravel migration. you can easy and simply change length using laravel migration.

This simple article demonstrates of change column length laravel migration. We will use laravel migration change column length. Here you will learn laravel change column length migration. I’m going to show you about migration change column length in laravel.

we are managing proper length of data type then it's very help full for db storage. we can save space. but if you added length like 50 with string data type and latter you need to upgrade it then how you will do.

Migration:


<?php

use Illuminate\Support\Facades\Schema;

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Database\Migrations\Migration;

class CreateBlogsTable extends Migration

{

/**

* Run the migrations.

*

* @return void

*/

public function up()

{

Schema::create('blogs', function (Blueprint $table) {

$table->bigIncrements('id');

$table->string('title', 50);

$table->text('body');

$table->timestamps();

});

}

/**

* Reverse the migrations.

*

* @return void

*/

public function down()

{

Schema::dropIfExists('blogs');

}

}

Change Column Length using Migration

now, we need to update title string 50 length to 100. we can do it with following migration:

Install Composer Package:

composer require doctrine/dbal

Migration:

<?php

use Illuminate\Support\Facades\Schema;

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Database\Migrations\Migration;

class UpdateBlogsTable extends Migration

{

/**

* Run the migrations.

*

* @return void

*/

public function up()

{

Schema::table('blogs', function (Blueprint $table) {

$table->string('title', 100)->change();

});

}

/**

* Reverse the migrations.

*

* @return void

*/

public function down()

{

}

}

I hope it can help you...

#Laravel 8

#Laravel 7

#Laravel

#Laravel 6