I have a table named replies contains all replies of a topic in a Forum laravel application.
**replies Table**
---------------
reply_id
content
topic_id
reply_by
embed_reply
created_at
updated_at
replies can have another reply Herself.fo that there is embed_reply column that hold reply_id of included reply.
Now I want details of included reply would have existed on the parent Reply on fetching.
for that i add this Method to reply Model :
public function included_reply ()
{
return $this->with('replies', function ($query) {
$query->where('reply_id',$this->embed_reply);
});
}
And for fetching replies of a specific Topic, I wrote this :
$topic = Topic::whereTopicId($id)
->with([
'replies' => function ($query) {
$query->orderBy('created_at', 'desc');
}
, 'replies.included_reply'
])
->first();
all of this return bellow Error:
BadMethodCallException in Builder.php line 2071:
Call to undefined method Illuminate\Database\Query\Builder::replies()
and I do not know how to do that. what is solution?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire