How can i get a limited items from relationship with Laravel
this is my laravel code:
$data = $category->posts;
i want something like:
$data = $category->posts->limit(4);
How can i get a limited items from relationship with Laravel
this is my laravel code:
$data = $category->posts;
i want something like:
$data = $category->posts->limit(4);
Define a separate relationship with the limit (or change posts()
):
public function postsLimited() {
return $this->posts()->limit(4);
}
$data = $category->postsLimited;