作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 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/
我正在使用 git clone 部署我的 Laravel 项目并使用 git pull 进行更新 它工作正常,但每次部署时,我都必须从 config/app.php providers 数组和 ali
我是一名优秀的程序员,十分优秀!