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

What is that you want to achieve exactly?

And are you aware that this:

$categories = Category::with(['posts'=> function($query)
{
    $query->take(4);
}])->get()

is going to limit all related posts (total 4 posts will be loaded, not 4 per category)

Last updated 2 years ago.
0

yes, i am aware of it. what i want to do is.

get all categories and 4 posts in it.

when somewhere in the view, i get to filter to get the category with name = 'sports'

Last updated 2 years ago.
0

The filter you have there is correct. So what is the issue?

Last updated 2 years ago.
0

Can you not do $sport->posts() ?

Anyway, do a dd($sports) . It will help you get a view of all properties of the $sports object.

Last updated 2 years ago.
0

mcraz said:

Can you not do $sport->posts() ?

Anyway, do a dd($sports) . It will help you get a view of all properties of the $sports object.

i can't, the scenario is this, i need to filter the posts because i will display 4 posts per category in the frontpage, and the order is manually arranged.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

alainbelez alainbelez Joined 11 Feb 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.