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

Found the solution:

$customers = Customer::all();

$customers->each(function($customer) {
	$customer->bills = $customer->bills->filter(function($bill) {
		if($bill->foo == 'bar')
			return true;

		return false;
	})
});
Last updated 1 year ago.
0

Hmm... I think it would be better to do the filtering within the model (either customers or bills, idk yet). But don't can figure out how to do that. Any ideas?

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

nehalist nehalist Joined 24 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.