I am trying to retrieve a polymorphic model that has null on its polymorphic columns. Based on the example below, how to retrieve comments that do not belong to any post or video
Example:
posts
id - integer
title - string
body - text
videos
id - integer
title - string
url - string
comments
id - integer
body - text
commentable_id - integer
commentable_type - string
Relationships:
class Comment extends Model
{
public function commentable()
{
return $this->morphTo();
}
}
class Post extends Model
{
public function comments()
{
return $this->morphOne('App\Comment', 'commentable');
}
}
class Video extends Model
{
public function comments()
{
return $this->morphOne('App\Comment', 'commentable');
}
}
via Chebli Mohamed
I am also looking for solution to this issue. Please share your answer as soon as you get one.
RépondreSupprimerLaravel Web Development Services