Kamran G. Kamran G. - 2 years ago 190
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)

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download