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

May a single post have multiple categories with the same name ("headlines" in this case)?

Last updated 2 years ago.
0

post have multiple categories, "headlines" are one of them.. and no, a single post, can't have 2 "headlines" category or any 2 same category

what i need to do is, sort the posts, dpending on the category.

Last updated 2 years ago.
0

In that case, I think something like this could be done (never tested it, though):

$headlines = Post::with(array('categories' => function($query) {
    $query->where('name', 'headlines');
}))->whereHas('categories', function($query) {
    $query->where('name', 'headlines');
})->where('published_at', Session::get('date'))->get()->sortBy(function($post) {
    return $post->categories->first()->id;
});
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.