how about $request->has('salesperson_id')
Distinguish between null and undefined in Request
I want to be able to give users the ability to nullify an existing value, salesperson_id in this example, through an external API call. My thought was that they could send a property with a value of null, but I also need to be able to preserve values when the property is absent from the request. I've tried isset(), empty(), is_null(), $request->salesperson_id === null and everything evaluates the same way.
Can PHP/Laravel differentiate between a property that is set to null and one that hasn't been defined at all?
To illustrate further, here are three possible calls with the desired outcome in the comments:
{
"order_id": 1234,
"salesperson_id": 246913022 // integer value gets assigned... this works fine
}
...
{
"order_id": 1234,
"salesperson_id": null // salesperson_id value should become null... also works fine
}
...
{
"order_id": 1234,
// salesperson_id property not set so any previously assigned value should remain unaffected, but this results in $request->salesperson_id === null and is nullifying a value that I want to preserve
}
Thanks!
Please or to participate in this conversation.