php - Is it possible to split query builder in Laravel? -
is possible split queries somehow this?
public function getstatuses($dates) { $query = db::table('tickets'); if ($dates['from']) $query = $query->where('from', $dates['from']); if ($dates['to']) $query = $query->where('to', $dates['to']); $query = $query->select('active'); return $query->get()->toarray(); }
yes, it's possibile. don't reassign same variable or risk messing up:
public function getstatuses($dates) { $query = db::table('tickets'); if ($dates['from']) $query->where('from', $dates['from']); if ($dates['to']) $query->where('to', $dates['to']); $query->select('active'); return $query->get()->toarray(); }
Comments
Post a Comment