Level 1
Mar 4, 2019
4
Level 1
Is this a good way to include the previous and next record?
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.
@if($portfolioItem->getPreviousRecord())
<div>
<a class="d-block" href="{{ route('portfolio.show', $portfolioItem->getPreviousRecord()->id) }}">
Vorig Werk
</a>
<h5 class="d-none d-md-block">{{ $portfolioItem->getPreviousRecord()->title }}</h5>
</div>
@endif
Please or to participate in this conversation.