Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

theone's avatar

Call to undefined method Illuminate\Database\Eloquent\Builder::addEagerConstraints()

I'm having Two table Booking and services i'm getting all bookings like Booking::get()->load('getServices'); In my booking model , public function getServices() { return Services::whereIn('id',explode(',',$this->extra_service)); } i saved selected service ids in comma separated in the field extra_service ,Please someone help to slove this

0 likes
3 replies
neilstee's avatar

@theone you might need to put get() on your method:

public function getServices()
{
	return Services::whereIn('id',explode(',',$this->extra_service))->get();
}

Also, try calling it like this:

Booking::with('getServices')->get();
SilenceBringer's avatar

@theone you'll not be able to use it this way

Relation can't depends on current model value (like you try to use it here whereIn('id',explode(',',$this->extra_service)), because this value is different for every specific model, and you can't get ot for collection at once

I recommend to use pivot table to store selected services. This way you'll be able to use eager loading

Please or to participate in this conversation.