I'll start directly off with my example. The thing is, I have a couple of hasMany
and belongsTo
relationships and I'd like to access a property of one of the returned object as a key in a where clause.
Let's say I have a model named Price
and it has three belongsTo
connections to three models named profileSystem
, profileType
and colorGroup
. Each of my three other models have a hasMany
connection to the Price
model.
So if I have an instance of my profileType
model, I'd like to call it's price where accordingly the profileSystem
and the colorGroup
parents will have some certain values. Example that works:
App\ProfileType::find(1)
-> prices -> where('profileType', App\ProfileType::find(1))
-> where('colorGroup', App\ColorGroup::find(1))
-> first()->value;
As you can see, the comparison here works directly with the whole instances of the colorGroup
and profileType
models that belong with the Price
model. What I'd like to do is no to compare the whole models, but only a single property, like so:
->where('colorGroup->id', 1)
or
->where('colorGroup->id', App\ColorGroup::find(1) -> id)
The question is all syntax that I'm not common with in laravel. I also couldn't find anything in the documentation. Thanks in advance!