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

sedev's avatar

Having clause doesn't work with PostgreSQL

Was working on porting a project in MySQLto PostgreSQL.

And this was the part where I retrieve the users with whom the photo is shared with. This was working as expected when I was using MySQL. Then I ported to PostgreSQL and this line stopped working.

    $sharedWith = $photo->users()->having('permission', '!=', 'owner')->get();

Changed that line to this and everything works fine now.

    $sharedWith = $photo->users()->where('photo_user.permission', '!=', 'owner')->get();

But I believe that someone must look into this since having() is an inbuilt Laravel function and is not supposed to break when I change the DB.

0 likes
1 reply
michaeldyrynda's avatar

Define 'not working'. How did it stop working, was it constructing a query that failed, did the function not execute at all? Was there any error messages?

Please or to participate in this conversation.