Crazylife's avatar

How to convert camel case into snake case when store into database as json?

I have an entity as shown below

class Entity {

public string uuid;
public string customerName;
......
}

In my controller

$data = collect(new Entity (
'b5b436f6-7a8b-4a5b-ae59-3754517d4ada'
'John'
))->toJson();

When converted into json, it will show {"uuid":"b5b436f6-7a8b-4a5b-ae59-3754517d4ada", "customerName":"John"}', i want it to be {"uuid":"b5b436f6-7a8b-4a5b-ae59-3754517d4ada", "customer_name":"John"}'

0 likes
1 reply

Please or to participate in this conversation.