Php 数组和stdObject到数据库的混合解码

Php 数组和stdObject到数据库的混合解码,php,mysql,json,laravel-4,Php,Mysql,Json,Laravel 4,我试图将一组json文件解码到一个mysql数据库中,并将解码后的值返回到一个datatable中进行表示。我有一个名为ec2_实例的表,希望向该表发送一个位于cfi配置中的值数组,该配置工作正常。但是现在我添加了一个名为aws account id的新列,它位于对象而不是数组上。我已经更新了模型以包含新列,但我正在努力 <?php function from_camel_case($input) { preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A

我试图将一组json文件解码到一个mysql数据库中,并将解码后的值返回到一个datatable中进行表示。我有一个名为ec2_实例的表,希望向该表发送一个位于cfi配置中的值数组,该配置工作正常。但是现在我添加了一个名为aws account id的新列,它位于对象而不是数组上。我已经更新了模型以包含新列,但我正在努力

<?php 
function from_camel_case($input)
{
    preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);
    $ret = $matches[0];
    foreach ($ret as &$match)
    {
        $match = $match == strtoupper($match) ? strtolower($match) : lcfirst($match);
    }
    return implode('_', $ret);
}
$resource_types = array();
$resource_types['AWS::EC2::Instance'] = 'EC2Instance';
$resource_types['AWS::EC2::NetworkInterface'] = 'EC2NetworkInterface';
$resource_types['AWS::EC2::VPC'] = 'VPC';
$resource_types['AWS::EC2::Volume'] = 'Volume';
$resource_types['AWS::EC2::SecurityGroup'] = 'EC2SecurityGroup';
$resource_types['AWS::EC2::Subnet'] = 'Subnet';
$resource_types['AWS::EC2::RouteTable'] = 'RouteTable';
$resource_types['AWS::EC2::EIP'] = 'EIP';
$resource_types['AWS::EC2::NetworkAcl'] = 'NetworkAcl';
$resource_types['AWS::EC2::InternetGateway'] = 'InternetGateway';


$accounts = DB::table('aws_account')->get();
$account_id = array($accounts);
$account_id_exists = array_add($account_id, 'key', 'value');     




foreach(glob('../app/views/*.json') as $filename)
{
    //echo $filename;
    $data = file_get_contents($filename);

    if($data!=null)

    {


            $decoded=json_decode($data,true);  


            if(isset($decoded["Message"])) 
            { 
            //echo "found message<br>";
                $message= json_decode($decoded["Message"]);
if(isset($message->configurationItem))
{
//  echo"found cfi<br>";    
            $insert_array = array();
                $cfi = $message->configurationItem;
                switch ($cfi->configurationItemStatus)
                {

                    case "ResourceDiscovered":
                //echo"found Resource Discovered<br>";  
                        if (array_key_exists($cfi->resourceType,$resource_types))

                        {

                            //var_dump($cfi->resourceType);
                            $resource = new $resource_types[$cfi->resourceType];

                            foreach ($cfi->configuration as $key => $value)
                            {
                                if (in_array($key,$resource->fields))
                                {
                                    $insert_array[from_camel_case($key)] = $value;
                                }
                            }






                            if (array_key_exists($cfi->awsAccountId,$resource_types))

                        {
                            $resource = new $resource_types[$cfi->awsAccountId];

                            foreach ($cfi->awsAccountId as $key => $value)
                            {
                                if (in_array($key,$resource->fields))
                                {
                                    $insert_array[from_camel_case($key)] = $value;
                                }
                            }









                            $resource->populate($insert_array);
                            if (!$resource->checkExists())
                            {
                                $resource->save();