Support the ongoing development of →
posted 5 years ago
Last updated 10 months ago.


I do not thing it is possible to achieve this by using Laravel relationships. The second parameter in hasMany is expected to be a string, which is why your DB:Raw expression is treated as such.

Try to change your approach. Instead of hasMany() try using

return BrandUser::where(DB:Raw('HEX(user_id)'), $this->id);

I am not sure if that will support operations like


Or maybe you can somehow add a new column, HEX(user_id) as hex_id, to the table when querying brand_users.

Last updated 5 years ago.

Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2023 - All rights reserved.