I am using the Laravel 5.7 PHP framework for this. I am storing client data based on their email address. The client data 'orders' field is of type JSON. Each time the client uses their email to make an order, I want to check if a record exists with that email, if it does, it will pull the order JSON from that record and add the new order, if not, it will create a new model make a new record.
I get the following exception: "Array to string conversion". When tracing, I find that it comes from this line of code which follows the convention from Laravel 5.7 documentation:
$client_data = ClientData::firstOrNew(['email' => $request->email]);
This is what I have in my ClientData
Model:
protected $table = ['client_data'];
protected $guarded = ['created_at'];
I verified that the $request->email
is indeed a string with an email address in it.
I also tried it with the following line of code, but got the same exception thrown:
$client_data = ClientData::where('email', $request->email)->first() ?: new ClientData(['email' => $request->email]);