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