/**
  * @param $query
  * @return \Closure
  */
 protected function buildSubQuery($name, $query)
 {
     if (empty($query['callback']) || !is_callable($query['callback'])) {
         $subQuery = new FilterSubQuery($query);
         if (!$subQuery->validate()) {
             $this->throwInvalidSubQueryException($name);
         }
         $query = function ($q) use($subQuery) {
             $q->where($subQuery->column, $subQuery->operator, $subQuery->value);
         };
     } else {
         $query = $query['callback'];
     }
     return $query;
 }
 /**
  * @param $name
  * @param array|closure $query
  */
 protected function addEagerLoad($name, $query)
 {
     if (count($query) == 0 || $query == $name) {
         $this->builder->with($name);
         return;
     }
     if (empty($query['callback']) || !is_callable($query['callback'])) {
         $subQuery = new FilterSubQuery($query);
         if (!$subQuery->validate()) {
             $this->throwInvalidSubQueryException($name);
         }
         $query = function ($q) use($subQuery) {
             $q->where($subQuery->column, $subQuery->operator, $subQuery->value);
         };
     } else {
         $query = $query['callback'];
     }
     $this->builder->with([$name => $query]);
 }