Skip to content

Instantly share code, notes, and snippets.

@dillingham
Last active January 23, 2019 05:23
Show Gist options
  • Save dillingham/0dee4247548275185ed1fa604dad96f2 to your computer and use it in GitHub Desktop.
Save dillingham/0dee4247548275185ed1fa604dad96f2 to your computer and use it in GitHub Desktop.

Within comment resource

public static $searchRelations = [
    'post' => ['title'],
    'video' => ['title'],
];

And here is the comment model

class Comment {

    public function commentable() {
        return $this->morphTo();
    }
    
    public function post() {
      return $this
        ->belongsTo('App\Post', 'commentable_id')
        ->where('commentable_type', 'App\Post');
    }
    
    public function video() {
      return $this
        ->belongsTo('App\Video', 'commentable_id')
        ->where('commentable_type', 'App\Video');
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment