How can I access data via relationship

Posted 2 months ago by Melodia

I have a user that has many properties. This is user should also be able tp view the offers bet on his properties.

So have the relationship set.


public function properties(){
    return $this->hasMany('App\Property');


public function offers(){
    return $this->hasMany('App\Offer');

Then in my controller this is what I have:

public function my_offers(){
    $properties = Property::whereUserId(Auth::id())->get();

    return view('pages.seller.offers.index', compact('properties'));

Then I go to my views like this:

    @foreach($properties as $property)



When I view the page I see the below error:

Property [offer_message] does not exist on this collection instance.

But this property exists in my table.

If I change my list item to the one below I can see the array:


I also see that before and after the array with the data, there are two empty arrays.

Is there anything that I didnt correctly?

Hope someone can help

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.