6 months ago

Is this a good way to include the previous and next record?

Posted 6 months ago by MiguelStevens

I'm wondering if my method of including the next and previous records, are according to good (OOP/Laravel) standards.

In my Model class, I include the following methods

class PortfolioItem extends Model
    public function getPreviousRecord()
        return PortfolioItem::where('id', '<', $this->id)->first();

    public function getNextRecord()
        return PortfolioItem::where('id', '>', $this->id)->first();

Then I check in my view if the returned result is not null, and render those items.

        <a class="d-block" href="{{ route('portfolio.show', $portfolioItem->getPreviousRecord()->id) }}">
            Vorig Werk
        <h5 class="d-none d-md-block">{{ $portfolioItem->getPreviousRecord()->title }}</h5>

Please sign in or create an account to participate in this conversation.