use IlluminateDatabaseEloquentBuilder;
// Retrieve posts with at least one comment containing words like foo%...
$posts = AppPost::whereHas('comments', function (Builder $query) {
$query->where('content', 'like', 'foo%');
})->get();
// Retrieve posts with at least ten comments containing words like foo%...
$posts = AppPost::whereHas('comments', function (Builder $query) {
$query->where('content', 'like', 'foo%');
}, '>=', 10)->get();
public function index()
{
$countryName = 'Brazil';
$users = User::with('country')
->whereHas('country', function (Builder $query) use($countryName) {
$query->where('name', 'like', "%{$countryName}%");
})
->get();
}