gpt4 book ai didi

php - Laravel 在 Web 服务器的 View 中显示数据

转载 作者:行者123 更新时间:2023-11-29 03:18:41 25 4
gpt4 key购买 nike

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

如果我 dd 我的 Controller 给出结果。

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中的数据,然后尝试在条件下使用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;
?>

关于php - Laravel 在 Web 服务器的 View 中显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49344315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com