select properties.address, properties.unit_type, rents.date, rents.amount, lease_requests.security_deposit
from properties
left join rents on rents.property_id = properties.id
left join lease_requests on lease_requests.property_id = properties.id
where (rents.status = 'paid' and rents.date between '2019-01-07' and '2019-02-07')
or (lease_requests.security_deposit_status = 'paid' and lease_requests.move_in between '2019-01-07' and '2019-02-07')
How can I rewrite this sql query in Laravel, but not by using raw sql, but with combining ->join, ->where, ->orWhere? I know that I should use function within one of these, but I am not sure within which one would that be. Does all of those functions accept function as second parameter?
EDIT
Here is the code which I have written in order to accomplish this, but it's not retrieving exactly the same data as the sql code I have written up there, because I am not sure how to implement query with brackets using Laravel:
Property::join('rents', 'properties.id', '=', 'rents.property_id')
->leftJoin('lease_requests', 'properties.id', '=', 'lease_requests.property_id')
->where('properties.address', $property['address'])
->whereBetween('move_in', [$from,$to])
->whereBetween('date', [$from,$to])
->where('rents.status', 'paid')
->orWhere('security_deposit_status', 'paid')
->get(['properties.address', 'properties.unit_type', 'rents.date', 'rents.amount', 'lease_requests.move_in', 'lease_requests.security_deposit'])->toArray();