php - Undefined property: stdClass::$account_id error in my code -
i have encountered following error
undefined property: stdclass::$account_id (view: c:\xampp\htdocs\laravel\awsconfig\app\views\search.blade.php)
here code causing error :
$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_list = array(); foreach(glob('../app/views/*.json') $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 $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 $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 $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;
i know silly appreciate
base on code simple demonstartion explanning, db::select
returns array contains several objects (may more one), , assign to$this->food
.
remember, $this->food
looks like
array ( [0] => stdclass object ( [name] => 'beef' ) )
actually, $this->food->name trying access undefined property.
solution 1:
you should use $this->food[0]->name
access it.
thought looks weird, works.
solution 2:
why not call food::find($id)
fetch object instead of $food = new food($id)
you can learn more reading http://laravel.com/docs/eloquent
hope might in solving problem
Comments
Post a Comment