Пример #1
0
 /**
  * Get a paginator for the "select" statement.
  *
  * @param  int    $perPage
  * @param  array  $columns
  * @return \Pagination\Paginator
  */
 public function paginate($perPage = null, $columns = array('*'))
 {
     // Get the Pagination Factory instance.
     $paginator = $this->query->getConnection()->getPaginator();
     $perPage = $perPage ?: $this->model->getPerPage();
     if (isset($this->query->groups)) {
         return $this->groupedPaginate($paginator, $perPage, $columns);
     } else {
         return $this->ungroupedPaginate($paginator, $perPage, $columns);
     }
 }
Пример #2
0
 /**
  * Process an "insert get ID" query.
  *
  * @param  \Nova\Database\Query\Builder  $query
  * @param  string  $sql
  * @param  array   $values
  * @param  string  $sequence
  * @return int
  */
 public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
 {
     $results = $query->getConnection()->selectFromWriteConnection($sql, $values);
     $sequence = $sequence ?: 'id';
     $result = (array) $results[0];
     $id = $result[$sequence];
     return is_numeric($id) ? (int) $id : $id;
 }
Пример #3
0
 /**
  * Get a paginator only supporting simple next and previous links.
  *
  * This is more efficient on larger data-sets, etc.
  *
  * @param  int    $perPage
  * @param  array  $columns
  * @return \Nova\Pagination\Paginator
  */
 public function simplePaginate($perPage = null, $columns = array('*'))
 {
     $paginator = $this->query->getConnection()->getPaginator();
     $page = $paginator->getCurrentPage();
     $perPage = $perPage ?: $this->model->getPerPage();
     $this->query->skip(($page - 1) * $perPage)->take($perPage + 1);
     return $paginator->make($this->get($columns)->all(), $perPage);
 }
Пример #4
0
 /**
  * Process an  "insert get ID" query.
  *
  * @param  \Nova\Database\Query\Builder  $query
  * @param  string  $sql
  * @param  array   $values
  * @param  string  $sequence
  * @return int
  */
 public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
 {
     $query->getConnection()->insert($sql, $values);
     $id = $query->getConnection()->getPdo()->lastInsertId($sequence);
     return is_numeric($id) ? (int) $id : $id;
 }