I made a custom and simple blog module.
I'm trying to display, on the single article page, the next article and the previous one.
Then I tried, with help I got here, in the model
public function onRun (){
$this->articles = $this->getNextArticleAttribute();
$this->articles = $this->getPreviousArticleAttribute();
}
public function getNextArticleAttribute() {
return self::where('id','<', $this->id)->orderBy('id', 'ASC')->first();
}
public function getPreviousArticleAttribute() {
return self::where('id','>', $this->id)->orderBy('id', 'ASC')->first();
And in the single page
{% set previous = __SELF__.previousArticle() %}
<div class="wrapper-small">
<div id="single-pagination" class="blog-pagination fixed">
<ul class="pagination clearfix">
<li class="prev"><a href="/news/{{previous.slug}}" class="pseudo-ajax">
<span class="text">Précédent</span>
<span class="page-image"><span><img src="{{previous.newsimage.path}}" alt="SEO Name" /></span></span>
</a>
{% set next = __SELF__.nextArticle() %}
</li>
<li class="next "><a href="/news/{{next.slug}}" class="pseudo-ajax">
<span class="text">Suivant</span>
<span class="page-image"><span><img src="{{next.newsimage.path}}" alt="SEO Name" /></span></span>
</a></li>
</ul>
</div> <!-- END .single-pagination -->
</div> <!-- END .wrapper-small -->
So I really don't know what I'm missing...