gpt4 book ai didi

php - 拉维尔 : Trying to get property of non-object

转载 作者:行者123 更新时间:2023-12-02 00:14:23 24 4
gpt4 key购买 nike

我在使用 laravel 时遇到问题,在我的本地主机上一切正常,但在我的共享主机上我遇到了问题,即使是相同的 php 版本

例如:我想使用 $answer->question->title 获取问题标题,但在尝试获取非对象属性时出现错误( View :/new/resources/views/users/show.blade.php)但是该项目在我的本地主机上运行良好

Controller :

public function show($id)
{
$user = User::find($id);
$answers = \App\Answer::where('user_id','=',$user->id)
->with(['survey'])
->get();
$survey = \App\Survey::pluck('title', 'id')->toArray();
$question = \App\Question::pluck('title', 'id')->toArray();

return view('users.show', compact('user','survey','answers','question'));
}

查看 Blade :

 <table class="table">
<thead class="thead-light">
<tr>
<th>{{ __('Question') }}</th>
<th>{{ __('Answers') }}</th>
<th>{{ __('Creation Date') }}</th>
</tr>
</thead>
<tbody>
@foreach($answers as $t)
<tr>
<td> {{ $t->question->id }} </td>
<td> {{ $t->answer }} </td>
<td> {{$t->created_at}} </td>
</tr>
@endforeach
</tbody>
</table>

在我的本地主机上工作正常但在共享主机上我得到了:

错误异常(E_ERROR)试图获取非对象的属性( View :/new/resources/views/users/show.blade.php)以前的异常(exception)试图获取非对象的属性(0)

你能帮我解决这个问题吗?

最佳答案

试着这样调用它:

$article->question['title']

希望对您有所帮助!

关于php - 拉维尔 : Trying to get property of non-object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57501912/

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