code: public function queryHook()
      {
          return function ($next, $query, $bag) {
              $method = $bag->get('method');
              $args   = $bag->get('args');
              $column = $args->get('column');
  
              if (!$this->hasColumn($column) && $this->allowsMeta($column) && $this->isMetaQueryable($method)) {
                  return call_user_func_array([$this, 'metaQuery'], [$query, $method, $args]);
              }
  
              if (in_array($method, ['select', 'addSelect'])) {
                  call_user_func_array([$this, 'metaSelect'], [$query, $args]);
              }
  
              return $next($query, $bag);
          };
      }
docs: Register hook on queryHook method.
  
  @return \Closure