Laravel - Relationships - One To Many Polymorphic Retrieving The Relationship

Once your database table and models are defined, you may access the relationships via your model's dynamic relationship properties. For example, to access all of the comments for a post, we can use the comments dynamic property:

    
    use App\Models\Post;
    
    $post = Post::find(1);
    
    foreach ($post->comments as $comment) {
        //
    }
	

You may also retrieve the parent of a polymorphic child model by accessing the name of the method that performs the call to morphTo. In this case, that is the commentable method on the Comment model. So, we will access that method as a dynamic relationship property in order to access the comment's parent model:

    
    use App\Models\Comment;
    
    $comment = Comment::find(1);
    
    $commentable = $comment->commentable;
	

The commentable relation on the Comment model will return either a Post or Video instance, depending on which type of model is the comment's parent.