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

Davva's avatar
Level 10

Eager loading not working with particular UUID

I’ve been stuck on the weirdest problem for half a day now. I am using UUID(4) as primary keys on my models. I’ve stumbled on a UUID that seemingly breaks eager loading relationship:

Class User extends Authenticatable {
  // ...
  public function memberships() {
    return $this→hasMany('App\Membership');
  }
}
// this yields nothing even when I KNOW User has memberships associated in db
User::with('memberships')→find('624e114d-d914-4ee6-8bbf-1ee242acdce2');
// ..but skipping the with(..) will yield all user’s memberships for the same User
User::find('624e114d-d914-4ee6-8bbf-1ee242acdce2')→memberships;

Changing to any other UUID makes both examples above work, returning all related models. So it is specifically breaking on this particular ID.

This sounds super ridiculous, but.. What’s going on? (I'm on Laravel 7.2.2 / valet)

0 likes
2 replies
simeonoff's avatar

Hello and I came across the same problem with this uuid 933e4263-7cdb-4a58-a565-a885eb0e82db, after two days of searching for a solution I gave up and changed it, which means that I have to find a solution because nothing does not guarantee that it will not happen again.

Laravel 7.0

Please or to participate in this conversation.