Skip to content

Commit

Permalink
Update first() method and add docs
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Engebretson <[email protected]>
  • Loading branch information
adamgoose committed Oct 17, 2013
1 parent 5d8bb37 commit 0b0f396
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ When returning an array of items using the `get()` method, you may use the `offs

$documents = Prismic::collection('my-collection')->offset(1)->limit(1)->get();

Alternatively, you can use the `first()` method to set the limit to 1 and return a single instance of `\Prismic\Document`:

$document = Prismic::collection('my-collection')->first();
// same as
// $document = Prismic::collection('my-collection')->limit(1)->get();

To sort the results by a particular date field, you can use the `getBy()` method *instead of the `get()` method*:

$documents = Prismic::collection('your-collection')->getBy('your-date-field');
Expand Down
2 changes: 1 addition & 1 deletion src/Adamgoose/PrismicIo/Prismic.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public function getSlug($slug)
*/
public function first()
{
return $this->get()[0];
return $this->limit(1)->get();
}

}

0 comments on commit 0b0f396

Please sign in to comment.