Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0
Solution
$category = 'Laravel';

$posts = Post::with('user', 'category')->whereHas('category', function($query) use ($category) {
    $query->where('name', '=', $category);
})->get();

source: http://laravel.com/docs/eloquent#querying-relations

Last updated 2 years ago.
0

Well.. thanx Zenry :)

I skipped trough the solution found in the documentation cause of the use ($category).

Never to late to review my low knowledge of closures ;)

Last updated 2 years ago.
0

Thanks Zenry... this is exactly what I was looking for..

ste-m your previous solution also works fine.. Thanks for sharing

0

Sign in to participate in this thread!

Eventy

Your banner here too?

ste-m ste-m Joined 25 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.