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

Neeraj1005's avatar

SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'on' for column 'isChecked' at row 1 (SQL: insert into `rfqs` (`product_name`, `product_category_id`, `sub_category_id`, `product_quantity`, `unit_id`, `city`, `isChecked`, `details`, `user_id`

SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'on' for column 'isChecked' at row 1 (SQL: insert into `rfqs` (`product_name`, `product_category_id`, `sub_category_id`, `product_quantity`, `unit_id`, `city`, `isChecked`, `details`, `user_id`, `updated_at`, `created_at`) values (Watch, 1, 1, 1, 1, Delhi, on, ?, 37, 2020-12-31 11:10:16, 2020-12-31 11:10:16))

Basically this return error for checkbox. In my table isCheckedcolumn is boolean. And I try dd() it return on for isChecked value. Can anyone tells me how return true/false for isChecked? Controller Method

    public function store(Request $request)
    {
        $validatedData = $request->validate([
            'product_name' => 'required',
            'product_category_id' => 'required',
            'sub_category_id' => 'required',
            'product_quantity' => 'required',
            'unit_id' => 'required|not_in:0',
            'city' => 'required|',
            'isChecked' => 'required|accepted',
        ])+[
            'details' => $request->details,
            'user_id' => auth()->user()->id,
        ];

        Rfq::create($validatedData);

        return redirect()->withMessage('RFQ submitted successfully.');
    }
0 likes
8 replies
wingly's avatar

By default If the value attribute was omitted, the default value for the checkbox is on. You can either set the value attribute to the html element to 1 for example or handle this on your controller

tisuchi's avatar

@neeraj1005 It's because you set column type as an integer and providing some text (by default check box return on or off).

Probably you can set mutator here

public function setIsCheckedAttribute($value)
{
    $this->attributes['isChecked'] = (bool) $value;
}

Or on the migration file, just set the integer to string. Like that-

$table->string('isChecked');

Ref: https://stackoverflow.com/questions/42166853/store-true-as-1-false-as-0-using-laravel-eloquent-mysql

tisuchi's avatar

@neeraj1005 Yes, but once you submit the form, normally checkbox returns on or off based on whether you checked or not.

Since you directly create the value into the table, Rfq::create($validatedData); therefore it takes checkbox value as on. That's why I suggest whether you change the value as an attribute or change the table value to a string.

1 like
Neeraj1005's avatar

@tisuchi okk I tried it letter but I solve this problem using this conditional statements.

     $validatedData = $request->validate([
            'product_name' => 'required',
            'product_category_id' => 'required',
            'sub_category_id' => 'required',
            'product_quantity' => 'required',
            'unit_id' => 'required|not_in:0',
            'purchase_price' => 'nullable',
            'city' => 'required|',
            'isChecked' => 'required|accepted',
            'details' => 'nullable',
        ])+[
            'user_id' => auth()->user()->id,
        ];

        if (request('isChecked') === 'on') {
            $validatedData['isChecked'] = true;
        }
MichalOravec's avatar
Level 75

You should exclude that checkbox from your data and use has for checkbox

Rfq::create($request->except('isChecked') + [
    'isChecked' => $request->has('isChecked')
]);

This will work in your code

public function store(Request $request)
{
    $validatedData = $request->validate([
        'product_name' => 'required',
        'product_category_id' => 'required',
        'sub_category_id' => 'required',
        'product_quantity' => 'required',
        'unit_id' => 'required|not_in:0',
        'city' => 'required|',
        'isChecked' => 'required|accepted',
    ]) + [
        'details' => $request->details,
        'user_id' => auth()->user()->id,
        'isChecked' => $request->has('isChecked')
    ];

    Rfq::create($validatedData);

    return redirect()->withMessage('RFQ submitted successfully.');
}

By the way always use a form request instead of have a validation in the controller.

1 like
wingly's avatar

@neeraj1005 Just change your html like i said there is no reason to complicate things

2 likes

Please or to participate in this conversation.