Laravel-如何访问集合内的阵列
我试图通过Laravel从在线api获取一些提要。我的钱包里有这个:Laravel-如何访问集合内的阵列,laravel,Laravel,我试图通过Laravel从在线api获取一些提要。我的钱包里有这个: { "assetCount,": "96", "title": "testing", "description": "Users feedback", "articles": { "id": "206", "publishedTime": "234663266", "teaser": "*REI and VDC DEC teams to..." } } 模型 在foreach声明中我需要帮助。我如何为有(id,publish
{
"assetCount,": "96",
"title": "testing",
"description": "Users feedback",
"articles": {
"id": "206",
"publishedTime": "234663266",
"teaser": "*REI and VDC DEC teams to..."
}
}
模型
在foreach声明中我需要帮助。我如何为有(id,publishedTime,Trister)的文章完成它呢?你的
文章
代码在哪里?我不知道如何完成它你有文章
模型和表格吗?你的文章
代码在哪里?我不知道如何完成它你有文章
模型和表格吗?
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class SmsFeed extends Model
{
protected $table = 'sms_feeds';
protected $fillable = ['asset_count', 'title', 'description', 'published_time', 'teaser', 'smskey', 'category'];
}
$array_content=[];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.test.com/monk/1xhxiluh826bt7?_fmt=json&_rt=b&ctg=english%20football%20sms&_fld=tsr,pt&kwd=arsenal");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //Important
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
$result = curl_exec($ch);
//$array = json_decode($result, true);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
$plainXML = self::mungXML($result);
$arrayResult = json_decode(json_encode(SimpleXML_Load_String($plainXML, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
$i=0;
foreach($arrayResult['monk'] as $value)
{
$record=SmsFeed::where('id', $value['articles']['id'])->first();
if (!isset($record)) {
SmsFeed::create([
'sms_key' => $value['@attributes']['id'],
'category' => 'arsenal',
'asset_count' => $value['assetCount'],
'title' => $value['title']
]);
}
$i++;
}