Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel错误:尝试获取show.blade.php中非对象的属性_Php_Laravel 5.3 - Fatal编程技术网

Laravel错误:尝试获取show.blade.php中非对象的属性

Laravel错误:尝试获取show.blade.php中非对象的属性,php,laravel-5.3,Php,Laravel 5.3,我的代码在这里,如果您需要任何其他部分的代码,我也会提供这段代码 <div class="panel-heading ">Organization Profile</div> <table class="table table-striped"> <thead> <tr> <th>Attributes</th> <th>Values</th>

我的代码在这里,如果您需要任何其他部分的代码,我也会提供这段代码

 <div class="panel-heading ">Organization Profile</div>
  <table class="table table-striped">
    <thead>
     <tr>
      <th>Attributes</th>
      <th>Values</th>
     </tr>
    </thead>
    <tbody>
     <tr>
      <td>Org Name</td>
      <td>{{$org->name}}</td>
     </tr>
     <tr>
      <td>Owner Name</td>
      <td>{{$org->owner}}</td>
     </tr>
   </tbody>
  </table>
 </div>
组织简介
属性
价值观
组织名称
{{$org->name}
所有者名称
{{$org->owner}

当您返回数组时,试图获取非对象属性的问题通常出现在Laravel中,但尝试在blade文件中使用对象或根本不传递正确的对象字符串

我从注释中注意到,您正在传递函数中的
$org
,而不是
$org

public function create() { 
    return view('Admin.organizations.create',compact('orgs')); 
}
更新刀片文件,如下所示:

<div class="panel-heading ">Organization Profile</div>
<table class="table table-striped">
<thead>
 <tr>
  <th>Attributes</th>
  <th>Values</th>
 </tr>
</thead>
<tbody>
 <tr>
  <td>Org Name</td>
  <td>{{$orgs->name}}</td>
 </tr>
 <tr>
  <td>Owner Name</td>
  <td>{{$orgs->owner}}</td>
 </tr>
组织简介
属性
价值观
组织名称
{{$orgs->name}
所有者名称
{{$orgs->owner}

考虑到所有的评论,您的控制器中可能应该有如下内容:

public function show($id)
{
 $org = Organization::find($id);
 // $data = ['org', $id];
 return view('Admin.organizations.show')->with(compact('org'));
}
这是您的刀片视图:

<div class="panel-heading ">Organization Profile</div>
 @if (empty($org))
    <h1>Organization is empty</h1>
 @else 
    <table class="table table-striped">
       <thead>
        <tr>
         <th>Attributes</th>
         <th>Values</th>
        </tr>
       </thead>
       <tbody>
        <tr>
         <td>Org Name</td>
         <td>{{$org->name}}</td>
        </tr>
        <tr>
         <td>Owner Name</td>
         <td>{{$org->owner}}</td>
        </tr>
      </tbody>
     </table>
 @endif
</div>
组织简介
@if(空($org))
组织是空的
@否则
属性
价值观
组织名称
{{$org->name}
所有者名称
{{$org->owner}
@恩迪夫

当然,不知道组织模型中的内容会使我们无法知道所有者和名称是否作为模型的属性存在

我是初学者,请各位专家指导!控制器中的代码是什么?显然$org不是您想要的$org是空的,找出为什么控制器只有这样才能知道