I have a comments table that have comments of articles, recipes and products. So its a polymorphic
relation. I have two columns rel_id and rel_type
in my comments table those are being used for this relation.
Now in my Comment.php
I have following relation
public function rel()
{
$this->morphTo();
}
And in my other all classes I have following
public function comments()
{
return $this->morphMany('App\Models\Comment', 'rel');
}
When I try to get owner of comment and all its related data I found class not found error. For example
$comments = Comment::find(1);
echo $comments->rel_type //article
Now if I want to get data of article and when I try
$comments->rel
I found article class not found
. I am using namespace App\Models\Article
I have searched it out I found answer given here. When I try accepted answer, nothing happens, error remains same. When I try second answer of same question, I found
Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation
My ultimate goal is to get comment owner data like $comments->articles->id and so on. Please guide how can I do that?