mercredi 3 février 2016

Laravel - Retrieving an object by matching its collection/multidimensional array

I am looking for a way to retrieve an object by matching its multi dimensional array.

The structure I have is as follows:

ratefactor

id

factorname

ratevalues

id

ratefactorid

value

ratevaluegroups

rateid

ratevalueid

rate

id

amount

This would translate into having multiple factors combined to create a rate based on a combination of the values

For example I have:

ratefactors

AGE

COUNTRY

ratevalues

AGE:18

AGE:20

COUNTRY:USA

COUNTRY:UK

ratevaluegroups (pivot)

18, USA

20, USA

18, UK

20, UK

rates

18, USA, $100

20, USA, $150

18, UK, $175

20, UK, $200

Now what I would have being passed is AGE = 18 and COUNTRY = USA and I would have to return the rate $100. How would this be possible in Eloquent/Laravel? Also keep in mind that there could be more than the 2 factors COUNTRY and AGE.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire