krevitzr8584
krevitzr8584

I'm trying to develop a portfolio plugin and need to retrieve the previous or next item based on current item. In SQL, I would have to do the following:

select * from portfolio_items where id = (select min(id) from portfolio_items where id > 4)
select * from portfolio_items where id = (select max(id) from portfolio_items where id < 4)

where 4 is the id of the current item. How could I achieve this to make a method such that in the template, so that I can call {{ portfolioItem.previousUrl }} or {{ portfolioItem.nextUrl }}? Thanks in advance.

Hessel
Hessel

Did you found a solution for this?

jan-vince
jan-vince

You can look in Blog plugin source code. There are methods for previous/next records.

In Model you can create query like this:

public function nextRecord($currentId) {
$nextRecord = Record::where('id', '<>', $currentId)->where('id','>', $currentID)->orderBy('id', 'ASC')->first();
}

In Twig you can get nextRecord with {{ record.nextRecord }}.

You have to pass record to Twig from controller before you can use it.

Last updated

1-3 of 3