Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.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
Php LAVEL在Web服务器的视图中显示数据_Php_Mysql_Laravel_Laravel 5_Entity Relationship - Fatal编程技术网

Php LAVEL在Web服务器的视图中显示数据

Php LAVEL在Web服务器的视图中显示数据,php,mysql,laravel,laravel-5,entity-relationship,Php,Mysql,Laravel,Laravel 5,Entity Relationship,它给了我一个“试图获取非对象的属性”的错误,你能帮我吗?它在我的离线服务器上正常工作,但如果我在我的liveserver上上传它,它会给出一个错误 如果我添加控制器,我将给出结果 Collection {#287 ▼ #items: array:3 [▼ 0 => Branch {#297 ▼ #connection: "mysql" #table: null #primaryKey: "id" #keyType: "int"

它给了我一个“试图获取非对象的属性”的错误,你能帮我吗?它在我的离线服务器上正常工作,但如果我在我的liveserver上上传它,它会给出一个错误

如果我添加控制器,我将给出结果

Collection {#287 ▼
  #items: array:3 [▼
    0 => Branch {#297 ▼
      #connection: "mysql"
      #table: null
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:6 [▶]
      #original: array:6 [▶]
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #events: []
      #observables: []
      #relations: array:1 [▼
        "cashier" => User {#301 ▼
          #fillable: array:4 [▶]
          #hidden: array:2 [▶]
          #connection: "mysql"
          #table: null
          #primaryKey: "id"
          #keyType: "int"
          +incrementing: true
          #with: []
          #withCount: []
          #perPage: 15
          +exists: true
          +wasRecentlyCreated: false
          #attributes: array:8 [▼
            "id" => 5
            "name" => "qqqaMiracle Auer"
            "email" => "qqqapdickens@hotmail.com"
            "password" => "$2y$10$FArFw2M.dQBcsP4XAQ8a5.vYsfZHLp8S/6.1ZSaVGHaxuSKiYogbe"
            "usertype" => "cashier"
            "remember_token" => null
            "created_at" => "2018-01-22 03:30:20"
            "updated_at" => "2018-01-22 05:56:19"
          ]
          #original: array:8 [▶]
          #casts: []
          #dates: []
          #dateFormat: null
          #appends: []
          #events: []
          #observables: []
          #relations: []
          #touches: []
          +timestamps: true
          #visible: []
          #guarded: array:1 [▶]
          #rememberTokenName: "remember_token"
        }
      ]
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: []
      #guarded: array:1 [▶]
    }
    1 => Branch {#298 ▶}
    2 => Branch {#299 ▶}
  ]
}
但是当我用代码显示出纳的名字时。使用此代码

@foreach($dataBranch as $Branch)
<tr class="item{{$Branch->id}}">
<td> <a class="name">{{$Branch->branch_name}}</a> </td>
<td> <a class="name">{{$Branch->cashier->name}}</a> </td>
</tr>
@endforeach
@foreach($dataBranch作为$Branch)
{{$Branch->Branch_name}
{{$Branch->cashier->name}
@endforeach
它给了我一个“试图获取非对象的属性”的错误,你能帮我吗?它在我的离线服务器上正常工作,但如果我在我的liveserver上上传它,它会给出一个错误


请帮助

首先您需要调试foreach中的数据,然后尝试在条件中使用is_object()php函数以获得正确的数据字段

您可以通过以下方式验证数据:

<?php 
//verify your data
foreach($dataBranch as $Branch) {

var_dump($Branch);

if(is_object($Branch)) {
  if(!empty($Branch->id)) {
   echo '$Branch->id';
  }
}}
exit;
?>

错误消息准确无误,因为它表示您正试图访问非对象(
$Branch->cashier
)的属性(
名称

最可能的原因是其中一家分行可能没有出纳,因此您必须先检查
$Branch->cashier
是否存在,然后才能从中访问属性

{{ $Branch->cashier ?? $Branch->cashier->name : '' }}