Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Property [title] does not exist on the Eloquent builder instance

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>

enter image description here

like image 968
JohnSmith2521 Avatar asked Feb 27 '19 13:02

JohnSmith2521


2 Answers

I think you are missing the get() : $artikels = Artikel::where('id', $id)->get();

like image 62
user2018756 Avatar answered Nov 16 '22 03:11

user2018756


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>
like image 19
Ahmed Atoui Avatar answered Nov 16 '22 02:11

Ahmed Atoui