1

I am trying to insert an entire api response into a MySQL table using Laravel Eloquent but I am getting 'Array to string conversion' error. How do I solve this?

Please note, it is compulsory that I save the entire API response.

My API call

$response = Curl::to($url.$request->account_number)
                    ->withData($data)
                    ->asJson(true)
                    ->get();

My Query

 TransactionLog::create([
                        'payer' => $request->payer,
                        'amount' => $request->amount,
                        'phone' => $request->phone,
                        'response' => $response

                    ]);

1 Answer 1

1

Looks like you using ixudra/curl ?

With asJson(true) you will receive json_decode response, so if your plan is to save raw json response in the database you'll have to json_encode it like:

TransactionLog::create([
  'payer' => $request->payer,
  'amount' => $request->amount,
  'phone' => $request->phone,
  'response' => json_encode($response)
]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.