雄辩的生成器实例上不存在Laravel属性[title] [英] Laravel Property [title] does not exist on the Eloquent builder instance
本文介绍了雄辩的生成器实例上不存在Laravel属性[title]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试显示数据库中的数据时出现错误.此问题由在此网站上创建帖子的其他人发生.但是它们有一个foreach循环,而我没有.因此,针对此问题给出的所有答案均无效.
I am getting an error while trying to display data from the database.This problem occurred by other people who have created posts on this website. but they have a foreach loop and I don't. so all the answers given for this problem do not work.
文章控制器
public function showwereld($id)
{
$artikels = Artikel::where('id', $id);
return view('pages.show')->with('artikels', $artikels);
}
show.blade.php
<div class="row">
<div class="artikeltitel marginauto">
<div class="col-md-6 offset-md-3">
<h2>{{$artikels->title}}</h2>
<p style="font-weight: bold;">{{$artikels->intro}}</p>
<p>{{$artikels->body}}</p>
</div>
</div>
</div>
推荐答案
这在控制器上
public function index()
{
$artikel = Artikel::where('category_id', '1')->first();
return view('pages.wereld',compact('artikel'));
}
视图中:
<div class="row">
<div class="artikeltitel marginauto">
<div class="col-md-6 offset-md-3">
<h2>{{$artikel->title}}</h2>
<p style="font-weight: bold;">{{$artikel->intro}}</p>
<p>{{$artikel->body}}</p>
</div>
</div>
</div>
这篇关于雄辩的生成器实例上不存在Laravel属性[title]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文