Database table Column type is Boolean and nullable.
Value inserting to value is true or false:
$statusVal = $request->input('status');
if($statusVal == "yes"){
$toInsert = true;
}else if($statusVal == "no"){
$toInsert = false;
}
ServiceDetail::create(['status' => $toInsert]);
I want to insert null to $toInsert, if status is not selected
Please guide me through this
2
Answers
You can do it with a single statement using
nested-ternary-operator
.Just do it.
Try this, it will work.