Support the ongoing development of Laravel.io →
posted 6 years ago
Last updated 1 year ago.
0

Hi,

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

User::all()->with('brands')->get();

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

Last updated 6 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.