If you are using post as a model (without dependency injection), you can also do:
$posts = Post::orderBy('id', 'DESC')->get();
If you are using the Eloquent ORM you should consider using scopes. This would keep your logic in the model where it belongs.
So, in the model you would have:
public function scopeIdDescending($query)
{
return $query->orderBy('id','DESC');
}
And outside the model you would have:
$posts = Post::idDescending()->get();
More info: http://laravel.com/docs/eloquent#query-scopes
This is how I would go about it.
$posts = $this->post->orderBy('id', 'DESC')->get();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With