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

vanusi's avatar

1366 Incorrect decimal value Laravel

I have driver model with this condition :

protected $fillable = [
    'hourly_rate',
    'ot_hourly_rate',
    'commission_rate',
    'basic_salary',
    'join_date',
];

and here's my migration code :

public function up()
{
    Schema::table('drivers', function ($table) {
        $table->integer('hourly_rate', 24,2)->nullable()->default(0);
        $table->decimal('ot_hourly_rate', 24,2)->nullable()->default(0);
        $table->decimal('commission_rate', 24,2)->nullable()->default(0);
        $table->decimal('basic_salary', 24,2)->nullable()->default(0);
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{   
    Schema::table('drivers', function ($table) {
        $table->dropColumn('hourly_rate');
        $table->dropColumn('ot_hourly_rate');
        $table->dropColumn('commission_rate');
        $table->dropColumn('basic_salary');
    });
    }

the problem is when I try to create driver and didn't fill those field it says error decimal value. decimal can't store empty string as NULL at database ?

note : those field is not required.

0 likes
2 replies
jekinney's avatar

Your default is over riding the null value. Should be one or the other.

Ober4You's avatar

I have the same problem, and setting the column name with

->nullable(); or ->default(0);

doesn't help

this is due to the input field because an empty string is actually not equal to NULL and therefore default(0) doesn't take effect....so i think it needs to be checked if the input field is = "" then set that value to null....else save the value

Please or to participate in this conversation.