msiri
5 months ago

Retrieve relationships get null value

Posted 5 months ago by msiri

Hi there! I'm trying to load inside opportunity controller, my replies relative of a specific opportunity and also the association that writes them but i get a null value

  #relations: array:1 [▼
        "association" => null
      ]

This is my controller

public function show($id)
{

$opportunity = Opportunity::findOrFail($id);

$replies = Reply::where('opportunity_id', $opportunity->id)->with('association')->get();

return view('opportunity.show', compact('opportunity', 'replies'));

}

This is my opportunity.php

public function reply()
    {
        return $this->hasMany('Invisibili\Reply');
    }

My reply.php

  public function opportunity()
    {
        return $this->belongsTo('Invisibili\Opportunity');
    }

    public function association()
    {
        return $this->belongsTo('Invisibili\Association');
    }

and my association.php

    public function reply()
    {
        return $this->hasMany('Invisibili\Reply');
    }

Thanks for helping me!

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