Skip to content
Advertisement

Update Laravel Database table with cURL Get Response

I am trying to execute a cURL GET request and use the response to update my table, but getting the following error:

TypeError IlluminateDatabaseEloquentBuilder::create(): Argument #1 ($attributes) must be of type array, string given, called in /home/vagrant/code/bp/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php on line 23

A similar GET request through Postman returns the following response structure:

JavaScript

Controller: M3customCrudController.php

JavaScript

Advertisement

Answer

First – use Http facade, not curl.

Second – you get json (string) and not converting it in array.

Third – your model structure is same as response? I don’t think so.

Code may be like this, but it may be necessary to convert to fit the structure of the model

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement