Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mrtydn's avatar

Multiplication between 2 tables to bring up new field

I have 2 table, for room booking logic.

Calendar

id room_type_id date rate

1,1,2017-12-20,20.00 1,1,2017-12-21,20.00 1,1,2017-12-22,20.00 1,1,2017-12-23,20.00 1,2,2017-12-20,10.00 1,2,2017-12-21,10.00 1,2,2017-12-22,10.00 1,2,2017-12-23,10.00

Calculation

id room_type_id adult child multiply

1,1,2,0,2 - Room id : 1 - 2 adult 0 child 1,1,2,1,2.5 - Room id : 1 - 2 adult 1 child 1,2,2,0,1.5 - Room id : 2 - 2 adult 0 child 1,2,2,1,2.5 . Room id : 2 - 2 adult 1 child

I need calculate rate*multiply My parameter: adult:2, child:0, checkin_date: 2017-12-20>=, <checkout_date:2017:12-22

Result need: for new_rate : RoomId: 1 = 80 roomId: 2 = 30

But how i can do this, with Eloquent, or i need use RAW Query ?

Best.

0 likes
0 replies

Please or to participate in this conversation.