Laravel eloquent ORM group where -
how convert following query laravel 4 eloquent orm?
select * table ((starttime <= ? , endtime >= ?) or (starttime <= ? , endtime >= ?) or (starttime >= ? , endtime <= ?))
like this:
<?php $results = db::table('table') ->where(function($query) use ($starttime,$endtime){ $query->where('starttime', '<=', $starttime); $query->where('endtime', '>=', $endtime); }) ->orwhere(function($query) use ($otherstarttime,$otherendtime){ $query->where('starttime', '<=', $otherstarttime); $query->where('endtime', '>=', $otherendtime); }) ->orwhere(function($query) use ($anotherstarttime,$anotherendtime){ $query->where('starttime', '>=', $anotherstarttime); $query->where('endtime', '<=', $anotherendtime); }) ->get();
have @ documentation more cool stuff can eloquent , query builder.
//edit: wrap whole where-clause in braces (like in question), can this:
<?php $results = db::table('table') //this wraps whole statement in () ->where(function($query) use ($starttime,$endtime, $otherstarttime,$otherendtime, $anotherstarttime,$anotherendtime){ $query->where(function($query) use ($starttime,$endtime){ $query->where('starttime', '<=', $starttime); $query->where('endtime', '>=', $endtime); }); $query->orwhere(function($query) use ($otherstarttime,$otherendtime){ $query->where('starttime', '<=', $otherstarttime); $query->where('endtime', '>=', $otherendtime); }); $query->orwhere(function($query) use ($anotherstarttime,$anotherendtime){ $query->where('starttime', '>=', $anotherstarttime); $query->where('endtime', '<=', $anotherendtime); }); }) ->get();
Comments
Post a Comment