How to get posts in Laravel and show them on index.blade page but with different ID's of previous posts. In controller I have this code
$posts=Tblnewsarticles::limit(5)->get();
return view('index', ['posts' => $posts]);
Now I need more posts but with differents ID's than in $posts
variable
What you're looking for is pagination
Use:
$posts=Tblnewsarticles::paginate(5);
return view('index', ['posts' => $posts]);
For the links to the post pages, add the following to your index.blade.php:
{{ $posts->links() }}
If I understood correctly, you can use paginate
method in query builder from: https://laravel.com/docs/5.2/pagination#paginating-query-builder-results
public function index()
{
$posts = Tblnewsarticles::order_by('id', 'desc')->paginate(5);
return view('index', ['posts' => $posts]);
}
PS: It would be more helpful if you see how pagination works.
Hope this helps :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.