From 0b0f39612c1fa2bf5b41cd73ffbef32f407f41a8 Mon Sep 17 00:00:00 2001 From: Adam Engebretson Date: Thu, 17 Oct 2013 13:48:27 -0500 Subject: [PATCH] Update first() method and add docs Signed-off-by: Adam Engebretson --- README.md | 6 ++++++ src/Adamgoose/PrismicIo/Prismic.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 06a4229..c56b866 100644 --- a/README.md +++ b/README.md @@ -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'); diff --git a/src/Adamgoose/PrismicIo/Prismic.php b/src/Adamgoose/PrismicIo/Prismic.php index f52d36f..e3ae154 100644 --- a/src/Adamgoose/PrismicIo/Prismic.php +++ b/src/Adamgoose/PrismicIo/Prismic.php @@ -225,7 +225,7 @@ public function getSlug($slug) */ public function first() { - return $this->get()[0]; + return $this->limit(1)->get(); } } \ No newline at end of file