Actually, i confused to ask about the title for my problem.

i have the table comment like this

Schema::create('comments', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('user_id')->unsigned();
        $table->integer('parent_id')->unsigned()->nullable();
        $table->foreign('parent_id')->references('id')->on('comments')->onDelete('cascade');
            $table->text('body');
            $table->integer('commentable_id')->unsigned();
            $table->foreign('commentable_id')->references('id')->on('posts')->onDelete('cascade');
            $table->string('commentable_type');
            $table->timestamps();
    });

and my relationship to show reply from parent_id in Comment Model like this.

public function myreplyfrom()
{
    return $this->belongsTo(Comment::class,'parent_id')->select('body');
}

i show body comment in blade like this

@foreach($mycomments as $comment)                        
    <p> Reply from Comment-> {{ $comment->myreplyfrom }} </p>    
@endforeach

my comment table like this my comment table

and my comment dashboard like this my comment dashboard

what i've done is right to show the body of comment, but i want to remove {"body"}, so just comment without array and field title.

the result i expected is Reply from Comment-> sdsds and Reply from Comment-> woww

how to fix my problem??

1 Answers

2
Rajat Sharma On Best Solutions

You should use this in view for comment body of reply

@foreach($mycomments as $comment)
<p> Reply from Comment-> {{ $comment->myreplyfrom->body }} </p>
@endforeach