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.
article controller
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>
I think you are missing the get()
:
$artikels = Artikel::where('id', $id)->get();
this on controller
public function index()
{
$artikel = Artikel::where('category_id', '1')->first();
return view('pages.wereld',compact('artikel'));
}
in view:
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With