Search code examples
laraveleloquentmigrationlaravel-8

Laravel 8: Migrations how can i add string that is more than 1k characters?


Hello guys I have this migration? and I want the string of the table body up to 1000 characters. I think the default of characters in a string is 255. I hope you can help me because I need to input more than 700 strings. thanks guys

public function up()
{
    Schema::create('posts', function (Blueprint $table) {
        $table->id();
        $table->string('title');
        $table->string('body');
        $table->string('editedby');
        $table->timestamps();
    });
}

Solution

  • You can use longText

    $table->longText('body');
    

    The longText method creates a LONGTEXT equivalent column:

    Ref:https://laravel.com/docs/8.x/migrations#column-method-longText