Allow columns to be specified for Eloquent get, first, and paginate.

This commit is contained in:
Taylor Otwell 2011-08-17 18:32:48 -05:00
parent c95757175b
commit 9c9d0fe530
1 changed files with 7 additions and 5 deletions

View File

@ -194,8 +194,10 @@ public static function find($id)
*
* @return array
*/
private function _get()
private function _get($columns = array('*'))
{
$this->query->select($columns);
return Hydrator::hydrate($this);
}
@ -204,9 +206,9 @@ private function _get()
*
* @return mixed
*/
private function _first()
private function _first($columns = array('*'))
{
return (count($results = Hydrator::hydrate($this->take(1))) > 0) ? reset($results) : null;
return (count($results = $this->take(1)->_get($columns)) > 0) ? reset($results) : null;
}
/**
@ -215,7 +217,7 @@ private function _first()
* @param int $per_page
* @return Paginator
*/
private function _paginate($per_page = null)
private function _paginate($per_page = null, $columns = array('*'))
{
$total = $this->query->count();
@ -224,7 +226,7 @@ private function _paginate($per_page = null)
$per_page = (property_exists(get_class($this), 'per_page')) ? static::$per_page : 20;
}
return Paginator::make($this->for_page(Paginator::page($total, $per_page), $per_page)->get(), $total, $per_page);
return Paginator::make($this->select($columns)->for_page(Paginator::page($total, $per_page), $per_page)->get(), $total, $per_page);
}
/**