How To Add Default Value of Column in Laravel Migration

In this tutorial you will learn about the How To Add Default Value of Column in Laravel Migration and its application with practical example.

In this article, I’ll show you how to add default column value in laravel migration. You will learn learn to set defaule value of column while creating table using laravel migration.

How To Add Default Value of Column in Laravel Migration

Laravel migration provide default() and nullable() method to set default value of a column. In this example we will learn how to add default value as null, boolean, current time etc. In this step by step we will set default value of table column using migration in laravel.

Create Table Migration

Use the following artisan command to create table migration:

After the command executed you will notice a migration file created. Open migration file and put the following code in it:

database/migrations/YYYY_MM_DD_TIMESTAMP_create_products_table.php

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:

In this tutorial we have learn about the How To Add Default Value of Column in Laravel Migration and its application with practical example. I hope you will like this tutorial.