Kamran G. Kamran G. - 9 months ago 86
PHP Question

Laravel @foreach

I need to get each comments of news . Its working good for firstorFail() item


But bring me empty result when im try this one with foreach:

@foreach($news->comments() as $comment)


This: $news->comments() bringing you query builder probably. So what you need is to ->get() for execute query like this:

@foreach($news->comments()->get() as $comment)


or as a @Roy Philips mentioned: $news->comments