未找到Laravel 5 Model Class

时间:2015-05-14 08:59:43

标签: php laravel

我正在尝试将我的网络应用程序从laravel 4移植到5但我遇到的问题是找不到我的某个模型类。

我尝试使用命名空间,并拥有以下位于本地C:\xampp\htdocs\awsconfig\app\Models

的模型

错误出现的文件看起来像

<?php 
use App\Models\SecurityGroup;
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'] = 'SecurityGroup';
$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_list = array();




foreach(glob('../resources/sns messages/*.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;
                                }
                            }




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

                                    if(isset($cfi->configuration->tags))
                                    {
                                       foreach ($cfi->configuration->tags as $t )

                                        {

                                        $tag= new Tag;
                                    $tag->resource_type = "instance";

                                    $tag->resource_id = $resource->id;
                                    $tag->key = $t->key;
                                    $tag->value = $t->value;

                                    $tag->save();


                                        /*if(isset($cfi->awsAccountId))
                                    {

                                     foreach ($accounts as $a)

                                     {
                                       $account_list = $a->account_id;
                                     }


                                    if (!in_array($account_id,$account_list))
                                    {



                                    $account_id = new Account;
                                    $account_id->aws_account_id = $cfi->awsAccountId;

                                    $account_list[] = $account_id;
                                     $account_id->save();

                                        }        






                                } */
                                }
                                }




                            }

                        }

                        else
                        {
                            echo "Creating ".$cfi["resourceType"]." not yet supported<br>";
                        }





                    break;
                    case 'ResourceDeleted':
                    //  echo"found Resource Deleted<br>";
                        //ITEM DELETED
                        if (array_key_exists($cfi->resourceType,$resource_types))
                        {
                            //var_dump($cfi->resourceType);
                                                        $resource = new $resource_types[$cfi->resourceType];



                            if ($resource->checkExists($cfi->resourceId))
                            {
                                $resource->delete();
                                  if( isset($cfi->configuration->tags))
                                      {
                                        foreach ($cfi->configuration->tags as $t )

                                            {
                                             $tag= new Tag;
                                              $tag->resource_type = "instance";

                                              $tag->resource_id = $resource->id;
                                              $tag->key = $t->key;
                                              $tag->value = $t->value;
                                              if ($tag->checkExists($cfi->configuration->tags))
                                              {
                                               $tag->delete();
                                              }
                                        }


                                     }

                        }
                        }
                        else
                        {
                            echo "Deleting ".$cfi["resourceType"]." not yet supported<br>";
                        }
                    break;
                    case 'OK':
                        //echo"found Resource OK<br>";
                        //ITEM UPDATED




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

                                                        if ($resource->checkExists($cfi->resourceId))
                                                       {
                                                                foreach ($cfi->configuration as $key => $value)
                                                                {
                                                                        if (in_array($key,$resource->fields))
                                                                        {
                                                                                $update_array[from_camel_case($key)] = $value;
                                                                        }
                                                                }
                                $resource->populate($update_array);
                                                                $resource->save();
                                                        }        
                                                } 








                                                else
                                                {
                                                        echo "Updating ".$cfi["resourceType"]." not yet supported<br>";
                                                }
                    break;
                    default:
                        echo "Status ".$cfi['configurationItemStatus']." not yet supported<br>";
                    break;  

                    } 


            } 
        }
    }
}

和无法找到类的相应模型如下所示:

<?php namespace App\Models;
use Eloquent;
class SecurityGroup extends Eloquent
{
    protected   $table      = 'security_group';
    public      $timestamps = false;
    protected   $guarded    = array('id');

    public      $fields     = array('groupId',
                                    'groupName',
                                    'description',
                                    'ownerId'

                        );


    public function checkExists()
    {
        return self::where('group_id', $this->group_id)->first();
    }

    public function populate($array)
    {
        foreach ($array as $k => $v)
        {
            $this->$k = $v;
        }
    }
}

我迷失了导致问题的原因我没有看到任何拼写错误但是又一次又一次知道感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

解决资源类型需要完整的名称空间声明