Have you looked into Eloquent relationships?
Nov 25, 2018
5
Level 1
Querying foreign table in model.
Hi,
Two sql tables: products and colors Each color has id and name. Each product has top_color, side_color, bottom_color. All 3 are foreign keys with id from color table.
I want to write a product model in such a way that all queries will get me a name of the color, not it's id.
I can do it with accessor or mutator but there's got to be some nicer cleaner solution for this in Eloquent. After all, it's a very common problem.
Any suggestions appreciated.
Please or to participate in this conversation.