Try this one the line below each
dd($movie);
Or post the output of this commented out line
dd($this->index());
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Am trying to save data from an api to my database i have a function to fetch
public function index()
{
$client = new Client();
$uri = 'http://www.omdbapi.com/?t=tree&apikey=';
$header = ['headers' => ['X-Auth-Token' => 'My-Token']];
$res = $client->get($uri, $header);
$data = json_decode($res->getBody()->getContents(), true);
return $data;
}
And then a function to save in my db
public function store(Request $request)
{
$movies = $this->index();
// dd($this->index());
collect($movies);
foreach($movies as $movie) {
// dd($movie);
Movie::create([
'title' => $movie['Title'],
'year' =>$movie['Year'],
'type' =>$movie['Type'],
'cover_photo' => $movie['Poster'],
]);
}
}
When trying to save i get the error above
Please or to participate in this conversation.