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.
Sign in to participate in this thread!
We'd like to thank these amazing companies for supporting us
The Laravel portal for problem solving, knowledge sharing and community building.