jeudi 28 septembre 2017

How to fetch latest posts and specific post id at first in laravel eloquent

Is there way to fetch latest posts with pagination And I also want a specific post to first position in returned collection. I tried this...

Post::where(function ($query) {
    $query->where('status', 'draft')->orWhere('status', 'published');
})
->orWhere('id', 21)
->with(['author.profile'])
->orderBy('created_at', 'desc')
->paginate(3);

In this query I do get the 21 post id but it is on 3rd page. I want to get it on first place, I can I do this.

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire