Skip to content

Instantly share code, notes, and snippets.

@tnylea
Created April 20, 2017 17:39
Show Gist options
  • Save tnylea/34c815466e28eb2922b7cb880ceeda1f to your computer and use it in GitHub Desktop.
Save tnylea/34c815466e28eb2922b7cb880ceeda1f to your computer and use it in GitHub Desktop.
Post Model
<?php
class Post extends Model{
protected $appends = ['link', 'next'];
public function getLinkAttribute()
{
return route('single-post', ['category' => $this->category->slug,'slug' => $this->slug]).'/';
}
public function getNextAttribute()
{
$next_post = self::where('created_at', '>', $this->getOriginal('created_at'))->with('Category')->with('Author')->where('slug', '<>', $this->slug)->where('status', '=', 'PUBLISHED')->orderBy('created_at', 'ASC')->first();
return $next_post->link;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment