How To Add Default Value Of Column In Laravel Migration

Websolutionstuff | May-01-2023 | Categories : Laravel MySQL

In this article, we will explore how to add default values to columns in Laravel 10 migrations, although the information applies to Laravel 8 and 9 as well. Specifically, we will focus on adding default values to columns using Laravel migrations.

Laravel's migration system offers a convenient default() method that allows you to specify the default value for a column. Additionally, you can make use of the nullable() method to set a column as nullable.

Let's dive into the process of adding default values in Laravel 10 migrations, whether you need to set default values for an existing column, work with boolean defaults, or even use the current timestamp as a default. This knowledge is equally applicable to Laravel 8 and 9

Create Migration Command:

php artisan make:migration create_posts_table


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePostsTable extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('posts', function (Blueprint $table) {
            $table->text('description')->default('This is test description');
     * Reverse the migrations.
     * @return void
    public function down()

 1. Laravel Migration Default Value Null:



2. Laravel Migration Default Value Boolean:


3. Laravel Migration Default Value Current Date:


4. Laravel Migration Default Value with Update:



You might also like:

Recommended Post
Featured Post
How To Fixed Header In Datatable Using jQuery
How To Fixed Header In Datatab...

Data presentation and organization are easier with data tables. They help display information in an organized way. These...

Read More


Google Autocomplete Address In Laravel 9
Google Autocomplete Address In...

In this article, we will see the google autocomplete address in laravel 9. In laravel 8 google autocomplete address...

Read More


How To Create Custom Login Page In Django
How To Create Custom Login Pag...

In this article, we will see how to create a custom login page in django. how to allow user registration, login, an...

Read More


Target Class Does Not Exist In Laravel 8
Target Class Does Not Exist In...

In this article, we will see target class does not exist in laravel 8 and how to fix target class not found in...

Read More