Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry

Foreach on collection in laravel ?

Foreach on collection in laravel ?
 $comments = $post->comments()->with('replyComments:replyComments')->orderBy('created_at', 'desc')->get(); 

This needs to add to the fetch code.

then

 foreach ($comments as $comment) {
    echo $comment->replyComments;
}; 

Or else you can use array.

 displayData = [];
foreach ($comments as $comment) {
    displayData[] = $comment->replyComments;
};
echo displayData;

6 0

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online