Support the ongoing development of Laravel.io →
Eloquent Views Blade
Last updated 2 years ago.
0

Because it's not coming from a pagination.

Last updated 2 years ago.
0

Hi Fluzo,

Assign to a variable and then run the foreach loop as follow:

$posts = $tema->posts()->paginate(5);
@foreach($posts as $post)
   //make all you need with each $post object
@endforeach

Don't forget the closing tags for your blade foreach loop.

Hope it helps you.

Last updated 2 years ago.
0

codeATbusiness said:

Hi Fluzo,

Assign to a variable and then run the foreach loop as follow:

$posts = $tema->posts()->paginate(5); @foreach($posts as $post) //make all you need with each $post object @endforeach

Don't forget the closing tags for your blade foreach loop.

Hope it helps you.

That's correct, you should assign to a variable, but do so in your controller, not your view. Business logic should not be a view :)

Last updated 2 years ago.
0

ollieread said:

codeATbusiness said:

Hi Fluzo,

Assign to a variable and then run the foreach loop as follow:

$posts = $tema->posts()->paginate(5); @foreach($posts as $post) //make all you need with each $post object @endforeach

Don't forget the closing tags for your blade foreach loop.

Hope it helps you.

That's correct, you should assign to a variable, but do so in your controller, not your view. Business logic should not be a view :)

Yes ollieread, the better way could be a Repository to manage the relation between the Controller and the Data Layer.

Thanks for your comment.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

fluzo fluzo Joined 2 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.