Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rider's avatar
Level 1

creating new field with datatype in existing table laravel

Iam trying to create new field with datatype in existing table, i have done the migration and created new field but i can't give it's default value or datatype for newly created field can any one help me to do this..

artisan command i have written:

    php artisan make:migration add_firstname_to_users --table-users
   

My migration file up function looks like:

public function up()
{
    Schema::table('users', function (Blueprint $table) {
        $table->string('lastname');
    });
}

how can i declare dataype and it's default value for this newly created lastname..

0 likes
3 replies
IgorBabko's avatar

Hello -

$table->string('lastname')->default('<whatever default value in here>');
1 like
rider's avatar
Level 1

Thank you IgorBabko and DanielBanciulea your suggestions have helped me..

Please or to participate in this conversation.