I have a query like that
SELECT * FROM `sp_price` WHERE (`from_date` between '2014-08-15' and '2014-09-18') || (`to_date` between '2014-08-15' and '2014-09-18')
Now how I can convert this query in laravel 4
. I use Eloquent
I have a query like that
SELECT * FROM `sp_price` WHERE (`from_date` between '2014-08-15' and '2014-09-18') || (`to_date` between '2014-08-15' and '2014-09-18')
Now how I can convert this query in laravel 4
. I use Eloquent
maybe you can try this
In your example, you're checking both
from_date
andto_date
for the same range of dates...if this will always be the case, you can make this query a bit more "eloquent":In the SpPrice.php model:
Then, to call this method from a controller:
You can use
whereRaw()
to add a raw where clause to the query, for example:Or maybe you can use
DB::raw()
as first argument ofwhereBetween()
, but I'm not sure if it's possible, in that case you can useorWhere()
with a closure to write a more readable code, for example:But I'm not quite sure if this works, give it a try.