Laravel-如何访问集合内部的数组

时间:2019-06-11 15:31:01

标签: laravel

我正在尝试通过Laravel从在线api获取一些供稿。我的laravel中有这个:

<?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++;            
    } 

问题是,如何完成包含数组的文章。

{{1}}

在foreach语句中我需要帮助。如何为具有(id,publishedTime,预告片)的文章完成该操作

0 个答案:

没有答案