未定义的变量:属性(浏览:错误laravel 5

问题描述:

我想给一个变量传递给视图输出在这样做了以下错误抛出:未定义的变量:属性(查看:未定义的变量:属性(浏览:错误laravel 5

我知道错误是由于变量没有被拾起的看法,但我不知道为什么这里是我的代码

控制器其中$属性定义:

<?php 

namespace App\Http\Controllers; 

use Datatable; 
use View; 
use App\Models\EC2Instance; 
use App\Models\ChangedProperties; 
use Illuminate\Support\Facades\Input; 
use App\Models\ChangelogItem; 

class DetailsController extends Controller { 

    protected $layout = 'ec2_instance'; 

    public function changedproperties($resource_id, $resource_type) { 
     $changed_property = new ChangedProperties; 
     $changed_properties = $changed_property->where('resource_id', $resource_id)->where('resource_type', $resouce_type); 
    } 

    public function details($instance_id) { 

     $instance = new EC2Instance; 
     $instance_obj = $instance->where('instance_id', $instance_id)->first(); 

     $property = new ChangelogItem; 
     $properties = $property->where('resource_id', $instance_obj->id)->where('resource_type', 'ec2instance'); 

     // 
     $table = Datatable::table() 
       ->addColumn(
         'Changed Property', 'Change Type', 'Previous Value', 'Updated Value' 
       ) 
       ->setUrl('/ec2_instance/ec2instance/' . $instance_obj->id) 
       ->noScript(); 





     return View::make('ec2_instance')->with('instance', $instance_obj, $properties)->with('table', $table); 
    } 

    public function instance_details($resource_type, $resource_id) { 


     $query = ChangelogItem::select(array('message_id', 
          'type', 
          'changelog_item_id', 
          'created_at', 
          'updated_at', 
          'description')) 
         ->where('resource_id', $resource_id)->where('resource_type', $resource_type)->get(); 



     return Datatable::collection($query) 
         ->addColumn('message_id', function($model) { 
          $link2 = "<a href = '/changed_properties/" . $model->message_id . "' >" . $model->message_id . "</a>"; 
          return $link2; 
         }) 
         ->showColumns(
           'message_id', 'type', 'changelog_item_id', 'created_at', 'updated_at', 'description') 
         ->searchColumns('message_id', 'type', 'changelog_item_id', 'created_at', 'updated_at', 'description') 
         ->orderColumns('message_id', 'type', 'changelog_item_id', 'created_at', 'updated_at', 'description' 
         ) 
         ->make(); 
    } 

} 

,并查看

<!doctype html> 
<html lang="en"> 
    <head> 

     <title>Instance Details </title> 



     {!!HTML::style("css/jquery.dataTables.css")!!} 
     {!!HTML::script("js/jquery.js")!!} 
     {!!HTML::script("js/jquery.dataTables.min.js")!!} 

     <meta charset="UTF-8"> 
     <title>Config Search</title> 
     <style> 

      @import url(//fonts.googleapis.com/css?family=Raleway:700); 


      body { 
       margin:0; 
       font-family:'Raleway', sans-serif; 
       text-align:center; 
       color: #3a3a3d; 
      } 

      .welcome { 
       width: 300px; 
       height: 200px; 
       position: absolute; 
       left: 50%; 
       top: 50%; 
       margin-left: -150px; 
       margin-top: -100px; 
      } 

      a, a:visited { 
       text-decoration:none; 
      } 

      h1 { 
       font-size: 32px; 
       margin: 16px 0 0 0; 
      } 
     </style> 
    </head> 
    <body> 
     <div class="navigation-left" style="float:left"> 

      <a href="{!! url('/') !!}">Back </a> 
     </div> 








     <div class="row"> 
      <div class="col-md-12"> 

       <h3>Instance Details {!! $instance->instance_id !!}</h3> 



       <script language="Javascript"> 

        function formatAsUKDate(date) { 
         var date = new Date(); 
         var day = padWithZero(date.getDate(), 2); 
         var month = padWithZero(date.getMonth() + 1, 2); 
         var year = date.getFullYear(); 
         var hour = date.getHours(); 
         if (hour <= 9) 
          hour = '0' + hour; 
         var mins = date.getMinutes(); 
         if (mins <= 9) 
          mins = '0' + mins; 



         return day + '/' + month + '/' + year + ' ' + hour + ':' + mins; 
        } 

        function padWithZero(str, minLength) { 
         str = String(str); 
         while (str.length < minLength) { 
          str = '0' + str; 
         } 
         return str; 
        } 

        document.write("last refreshed: " + formatAsUKDate(document.lastModified) + ""); 
       </SCRIPT> 

      </div> 

      <table> 

       <tr><th>Instance ID</th><td>{!! $instance->instance_id !!}</td></tr> 
       <tr><th>Image ID</th><td>{!! $instance->image_id !!}</td></tr> 
       <tr><th>Private DNS Name</th><td>{!! $instance->private_dns_name !!}</td></tr> 
       <tr><th>Public DNS Name</th><td>{!! $instance->public_dns_name !!}</td></tr> 
       <tr><th>Key Name</th><td>{!! $instance->key_name !!}</td></tr> 
       <tr><th>Instance Type</th><td>{!! $instance->instance_type !!}</td></tr> 
       <tr><th>Launch Time</th><td>{!! $instance->launch_time !!}</td></tr> 
       <tr><th>Kernel ID</th><td>{!! $instance->kernel_id !!}</td></tr> 
       <tr><th>Subnet ID</th><td>{!! $instance->subnet_id !!}</td></tr> 
       <tr><th>VPC ID</th><td>{!! $instance->vpc_id !!}</td></tr> 
       <tr><th>Private IP Address</th><td>{!! $instance->private_ip_address !!}</td></tr> 
       <tr><th>Public IP Address</th><td>{!! $instance->public_ip_address !!}</td></tr> 
       <tr><th>Architecture</th><td>{!! $instance->architecture !!}</td></tr> 
       <tr><th>Root Device Type</th><td>{!! $instance->root_device_type !!}</td></tr> 
       <tr><th>Root Device Name</th><td>{!! $instance->root_device_name !!}</td></tr> 
       <tr><th>Virtualization Type</th><td>{!! $instance->virtualization_type !!}</td></tr> 
       <tr><th>Source Dest Check</th><td>{!! $instance->source_dest_check !!}</td></tr> 



       </table> 
     </div> 

     <table 
    <tr><th>Message ID</th><td>{!! $property->message_id !!}</td></tr> 
       <tr><th>Type</th><td>{!! $property->type !!}</td></tr> 
       <tr><th>Changelog Item ID</th><td>{!! $property->changelog_item_id !!}</td></tr> 
       <tr><th>Created</th><td>{!! $property->created_at !!}</td></tr> 
       <tr><th>Updated</th><td>{!! $property->updated_at !!}</td></tr> 
       <tr><th>Description</th><td>{!! $property->description !!}</td></tr> 
     </table> 

     {!! $table->render() !!} 

       {!! $table->script() !!} 






    </body> 

</html> 

$实例被发现尚未$ property不是。

那是因为你没有通过它在你看来 看看这里

return View::make('ec2_instance')->with('instance', $instance_obj, $properties)->with('table', $table); 

我想应该是这样的

return View::make('ec2_instance') 
     ->with('instance', $instance_obj) 
     ->with('property', $property) 
     ->with('table', $table); 

而且你似乎不是以取回从数据库的东西这里

$properties = $property->where('resource_id', $instance_obj->id)->where('resource_type', 'ec2instance'); 

此查询应以结尾方法如果您想要返回实例

get()如果您想要返回一个集合。