You can chain your where
s directly, without function(q)
. There's also a nice date handling package in laravel, called Carbon. So you could do something like:
$projects = Project::where('recur_at', '>', Carbon::now())
->where('recur_at', '<', Carbon::now()->addWeek())
->where('status', '<', 5)
->where('recur_cancelled', '=', 0)
->get();
Just make sure you require Carbon in composer and you're using Carbon namespace (use Carbon\Carbon;) and it should work.
EDIT: As Joel said, you could do:
$projects = Project::whereBetween('recur_at', array(Carbon::now(), Carbon::now()->addWeek()))
->where('status', '<', 5)
->where('recur_cancelled', '=', 0)
->get();
DB::raw
so no, there is no other way to do so using Eloquent on its own. On the other hand, how come you're using a DATETIME instead of TIMESTAMP column? What I'm asking is unrelated to original question, but TIMESTAMP fits better in many use cases compared to DATETIME. – N.B. Jul 18 '14 at 12:13