Polymorphic relationship

Posted 2 years ago by chezzemp

I have the following tables: Users, Videos, Post, Comments. (It is with the traditional relationship, Commentable, return $this->morphTo(), etc... The fault is in the consultation)

I have to make a polymorphic relationship, what happens is that users can only make one comment, the question is ... How to access that comment without using foreach?

It is currently like this.

@foreach($posts as $item)
    {{ $item->title }}
    //This is the problem, it is only a single comment, I would not like to use foreach
    @foreach($item->comments as $comment)
        {{ $comment->body }}

Many thanks friends,

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.