Example #1
0
 /**
  * @param null $params
  * @return array
  */
 public function tableData($params = null)
 {
     $with = $this->modelItem->getWith();
     if ($this->modelItem->isWithJoinEnabled()) {
         $baseQuery = $this->instance->newQuery()->getQuery();
         /** @var WithJoinEloquentBuilder $query */
         $query = new WithJoinEloquentBuilder($baseQuery);
         if ($this->modelItem->isAsync()) {
             $query->references($with);
         }
     } else {
         $query = $this->instance->newQuery();
     }
     $query->setModel($this->instance)->with($with);
     $query = $this->instance->applyGlobalScopes($query);
     $this->applyFilters($query);
     $totalCount = $query->count();
     if (!is_null($params)) {
         if (trim($params['search']) != '') {
             $search = '%' . $params['search'] . '%';
             $this->addSearchToQuery($query, $search);
         }
         $totalCount = $query->count();
         if ($params['limit'] != -1) {
             $query->offset($params['offset']);
             $query->limit($params['limit']);
         }
         if (!$this->instance instanceof ModelWithOrderFieldInterface) {
             $query->getQuery()->orders = null;
         }
         $query->orderBy($params['orderBy'], $params['orderDest']);
     }
     $rows = $query->get();
     return compact('rows', 'totalCount');
 }