nuna's avatar
Level 1

How to send value as null in db?

if($request->sys_status == 4){
            $sys_statu = 4;
            $role_val == NULL;
        }else{
            $sys_statu = $request->sys_status;
            $role_val = $request->role;
        }
0 likes
3 replies
zmance's avatar

Why don't you just make the "role_val" field nullable in the database and only send the value if the condition is true?

1 like
nuna's avatar
Level 1

the field is nullable in the db. this is a joined table.When I send the null value one table is updated and another one is not.I just need to makesure to set the value null iff sys_status = 4.Please help.And One table is set varchar and another is set int.

MichalOravec's avatar
Level 75

Your code could be just like this

$sys_statu = $request->sys_status;
$role_val = $sys_statu == 4 ? null : $request->role;
1 like

Please or to participate in this conversation.