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

kyurie's avatar

Laravel 8 checkbox

I want to store in database using checkbox, but when it is left unchecked. it gives error:

implode(): Argument #1 ($pieces) must be of type array, string given

StoreController:

$applications->ads = implode(',', $request->ads);
0 likes
6 replies
kyurie's avatar

How to make if statement using implode . if uncheck the database make it null .

databasetable:

$table->string('ads')->nullable();
jlrdw's avatar

If a checkbox is not checked nothing is passed, so you have to check for that in the request.

1 like
coder222's avatar
coder222
Best Answer
Level 1

As mentioned by jlrdw, you can check if the request passed the checkbox or not, you can use $request->has('cb_name')

1 like

Please or to participate in this conversation.