laravel - 将 api 数据保存到 db laravel 时出现非法字符串偏移“标题”
问题描述
我正在尝试将数据从 api 保存到我的数据库我有一个函数来获取
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;
}
然后一个函数保存在我的数据库中
public function store(Request $request)
{
$movies = $this->index();
// dd($this->index());
collect($movies);
// dd($movies);
foreach($movies as $movie) {
// dd($movie);
Movie::create([
'title' => $movie['Title'],
'year' =>$movie['Year'],
'type' =>$movie['Type'],
'cover_photo' => $movie['Poster'],
]);
}
}
尝试保存时出现上述错误
解决方案
推荐阅读
- powershell - 使用 ConvertToDateTme 变量创建 CSV
- kiba-etl - 使用 kiba ETL 检查 CSV 文件标头的最佳位置
- javascript - 总是得到“(0,_reactDom.h)不是函数”或“h未定义”
- java - 无法将命令代理到远程服务器。原始错误:错误:读取 ECONNRESET
- azure-active-directory - 从 Azure AD B2C 自定义策略调用受 OAuth 保护的 REST api
- pygame - 似乎无法同时选择多个圈子
- mobile - 带有附加/前缀下拉列表的文本表单
- optaplanner - 附近选择的条件概率分布 [Optaplanner]
- c# - 在 Visual Studio 的新解决方案中使用来自 github 的 Boostrap 模板
- c# - 是否存在 TaskPool 参考实现?